-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InputGen: introduce random manager (#7)
Summary: Pull Request resolved: #7 Introduces a random manager in InputGen. This allows to generate reproducible data, by seeding the random manager. ``` from inputgen.utils.random_manager import random_manager random_manager.seed(1729) ``` Reviewed By: zonglinpengmeta Differential Revision: D59668295 fbshipit-source-id: b69337d1f1a4b29e8589dbe4d26c0d7832466399
- Loading branch information
1 parent
a88dd7e
commit 3319ed9
Showing
9 changed files
with
136 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import torch | ||
from inputgen.argtuple.gen import ArgumentTupleGenerator | ||
from inputgen.utils.random_manager import random_manager | ||
from specdb.db import SpecDictDB | ||
|
||
|
||
def main(): | ||
# example to seed all random number generators | ||
random_manager.seed(1729) | ||
|
||
spec = SpecDictDB["add.Tensor"] | ||
op = torch.ops.aten.add.Tensor | ||
for ix, (posargs, inkwargs, outargs) in enumerate( | ||
ArgumentTupleGenerator(spec).gen() | ||
): | ||
op(*posargs, **inkwargs, **outargs) | ||
print( | ||
posargs[0].shape, | ||
posargs[0].dtype, | ||
posargs[1].shape, | ||
posargs[1].dtype, | ||
inkwargs["alpha"], | ||
) | ||
if ix == 1: | ||
print(posargs[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import random | ||
|
||
import torch | ||
|
||
|
||
class RandomManager: | ||
def __init__(self): | ||
self._rng = random.Random() | ||
self._torch_rng = torch.Generator() | ||
|
||
def seed(self, seed): | ||
""" | ||
Seeds the random number generators for random and torch. | ||
""" | ||
self._rng.seed(seed) | ||
self._torch_rng.manual_seed(seed) | ||
|
||
def get_random(self): | ||
# self._rng.seed(42) | ||
return self._rng | ||
|
||
def get_torch(self): | ||
# self._torch_rng.manual_seed(42) | ||
return self._torch_rng | ||
|
||
|
||
random_manager = RandomManager() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters