Skip to content

Commit e5f60c6

Browse files
authored
Remove views when not necessary (#1211)
* Update graph_mode_static_quantization_tutorial.py * Update transformer_tutorial.py * Update dynamic_quantization_tutorial.py
1 parent 1c1f40d commit e5f60c6

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

advanced_source/dynamic_quantization_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def batchify(data, bsz):
213213
def get_batch(source, i):
214214
seq_len = min(bptt, len(source) - 1 - i)
215215
data = source[i:i+seq_len]
216-
target = source[i+1:i+1+seq_len].view(-1)
216+
target = source[i+1:i+1+seq_len].reshape(-1)
217217
return data, target
218218

219219
def repackage_hidden(h):

beginner_source/transformer_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def batchify(data, bsz):
194194
def get_batch(source, i):
195195
seq_len = min(bptt, len(source) - 1 - i)
196196
data = source[i:i+seq_len]
197-
target = source[i+1:i+1+seq_len].view(-1)
197+
target = source[i+1:i+1+seq_len].reshape(-1)
198198
return data, target
199199

200200

prototype_source/graph_mode_static_quantization_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def accuracy(output, target, topk=(1,)):
137137

138138
res = []
139139
for k in topk:
140-
correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)
140+
correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
141141
res.append(correct_k.mul_(100.0 / batch_size))
142142
return res
143143

0 commit comments

Comments
 (0)