Skip to content

Commit 48a2058

Browse files
retonymfacebook-github-bot
authored andcommitted
Let random seed setting work on xpu device (#2270)
Summary: This Pull Request relates to [Roadmap Issue https://github.com/pytorch/benchmark/issues/1293](https://github.com/pytorch/benchmark/issues/1293) by enhancing our benchmark coverage. Currently, Torchbench utilizes a custom random seed function that is incompatible with the XPU device backend. This incompatibility affects models that include random data augmentation operations, leading to accuracy check failures due to variations in input data across two separate runs. In this PR, we introduce support for setting a random seed for the XPU backend. Pull Request resolved: #2270 Reviewed By: davidberard98 Differential Revision: D57884498 Pulled By: xuzhao9 fbshipit-source-id: 24234674333945782b233191e42a8b344e90d74c
1 parent a5f1710 commit 48a2058

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

torchbenchmark/util/env_check.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,12 @@ def deterministic_torch_manual_seed(*args, **kwargs):
172172

173173
seed = MAIN_RANDOM_SEED
174174
import torch.cuda
175-
176175
if not torch.cuda._is_in_bad_fork():
177176
torch.cuda.manual_seed_all(seed)
177+
178+
import torch.xpu
179+
if not torch.xpu._is_in_bad_fork():
180+
torch.xpu.manual_seed_all(seed)
178181
return default_generator.manual_seed(seed)
179182

180183
torch.manual_seed(MAIN_RANDOM_SEED)

0 commit comments

Comments
 (0)