Skip to content

Commit 1461544

Browse files
FindHaofacebook-github-bot
authored andcommitted
fix huggingface models input issue in torchbench (#126579)
Summary: Fixes #2263. According to https://github.com/pytorch/pytorch/blob/main/benchmarks/dynamo/common.py#L509, example_inputs are formatted as dictionaries for HuggingFace models. However, this forward_pass function passes all inputs to mod with *, which may only pass the input_ids key in HuggingFace model's example inputs. To reproduce, run the following command. ```bash python pytorch/benchmarks/dynamo/torchbench.py --performance --inference -dcuda --only=hf_Bert --output=torchbench_inference.csv ``` X-link: pytorch/pytorch#126579 Approved by: https://github.com/xuzhao9 Reviewed By: DanilBaibak Differential Revision: D57619425 Pulled By: FindHao fbshipit-source-id: 9074e227bab949c83768092cf019dfd590fe947b
1 parent b7524a6 commit 1461544

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

userbenchmark/dynamo/dynamobench/torchbench.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,19 @@ def compute_loss(self, pred):
423423

424424
def forward_pass(self, mod, inputs, collect_outputs=True):
425425
with self.autocast(**self.autocast_arg):
426-
return mod(*inputs)
426+
if isinstance(inputs, dict):
427+
return mod(**inputs)
428+
else:
429+
return mod(*inputs)
427430

428431
def forward_and_backward_pass(self, mod, inputs, collect_outputs=True):
429432
cloned_inputs = clone_inputs(inputs)
430433
self.optimizer_zero_grad(mod)
431434
with self.autocast(**self.autocast_arg):
432-
pred = mod(*cloned_inputs)
435+
if isinstance(clone_inputs, dict):
436+
pred = mod(**cloned_inputs)
437+
else:
438+
pred = mod(*cloned_inputs)
433439
loss = self.compute_loss(pred)
434440
self.grad_scaler.scale(loss).backward()
435441
self.optimizer_step()

0 commit comments

Comments
 (0)