assassinlike commited on
Commit
4880a67
·
verified ·
1 Parent(s): 0800294

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__init__.py +61 -0
  2. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/__init__.cpython-310.pyc +0 -0
  3. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/assume_constant_result.cpython-310.pyc +0 -0
  4. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/autograd_function.cpython-310.pyc +0 -0
  5. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/class_method.cpython-310.pyc +0 -0
  6. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_branch_class_method.cpython-310.pyc +0 -0
  7. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nested_function.cpython-310.pyc +0 -0
  8. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nonlocal_variables.cpython-310.pyc +0 -0
  9. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_closed_over_variable.cpython-310.pyc +0 -0
  10. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_operands.cpython-310.pyc +0 -0
  11. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_predicate.cpython-310.pyc +0 -0
  12. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/constrain_as_size_example.cpython-310.pyc +0 -0
  13. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/constrain_as_value_example.cpython-310.pyc +0 -0
  14. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/decorator.cpython-310.pyc +0 -0
  15. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dictionary.cpython-310.pyc +0 -0
  16. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_assert.cpython-310.pyc +0 -0
  17. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_constructor.cpython-310.pyc +0 -0
  18. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_if_guard.cpython-310.pyc +0 -0
  19. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_map.cpython-310.pyc +0 -0
  20. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_round.cpython-310.pyc +0 -0
  21. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_slicing.cpython-310.pyc +0 -0
  22. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_view.cpython-310.pyc +0 -0
  23. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/fn_with_kwargs.cpython-310.pyc +0 -0
  24. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/list_contains.cpython-310.pyc +0 -0
  25. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/list_unpack.cpython-310.pyc +0 -0
  26. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/model_attr_mutation.cpython-310.pyc +0 -0
  27. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/nested_function.cpython-310.pyc +0 -0
  28. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/null_context_manager.cpython-310.pyc +0 -0
  29. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/optional_input.cpython-310.pyc +0 -0
  30. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/pytree_flatten.cpython-310.pyc +0 -0
  31. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/scalar_output.cpython-310.pyc +0 -0
  32. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/specialized_attribute.cpython-310.pyc +0 -0
  33. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/static_for_loop.cpython-310.pyc +0 -0
  34. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/static_if.cpython-310.pyc +0 -0
  35. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/tensor_setattr.cpython-310.pyc +0 -0
  36. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/type_reflection_method.cpython-310.pyc +0 -0
  37. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/unsupported_operator.cpython-310.pyc +0 -0
  38. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/user_input_mutation.cpython-310.pyc +0 -0
  39. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/assume_constant_result.py +20 -0
  40. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/autograd_function.py +23 -0
  41. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/class_method.py +22 -0
  42. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_branch_class_method.py +44 -0
  43. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_closed_over_variable.py +22 -0
  44. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_operands.py +35 -0
  45. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_predicate.py +25 -0
  46. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/constrain_as_size_example.py +25 -0
  47. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/constrain_as_value_example.py +28 -0
  48. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/decorator.py +23 -0
  49. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/dictionary.py +17 -0
  50. data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/dynamic_shape_assert.py +18 -0
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__init__.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import dataclasses
3
+ import glob
4
+ import inspect
5
+ from os.path import basename, dirname, isfile, join
6
+
7
+ import torch
8
+ from torch._export.db.case import (
9
+ _EXAMPLE_CASES,
10
+ _EXAMPLE_CONFLICT_CASES,
11
+ _EXAMPLE_REWRITE_CASES,
12
+ SupportLevel,
13
+ export_case,
14
+ ExportCase,
15
+ )
16
+
17
+
18
+ def _collect_examples():
19
+ case_names = glob.glob(join(dirname(__file__), "*.py"))
20
+ case_names = [
21
+ basename(f)[:-3] for f in case_names if isfile(f) and not f.endswith("__init__.py")
22
+ ]
23
+
24
+ case_fields = {f.name for f in dataclasses.fields(ExportCase)}
25
+ for case_name in case_names:
26
+ case = __import__(case_name, globals(), locals(), [], 1)
27
+ variables = [name for name in dir(case) if name in case_fields]
28
+ export_case(**{v: getattr(case, v) for v in variables})(case.model)
29
+
30
+ _collect_examples()
31
+
32
+ def all_examples():
33
+ return _EXAMPLE_CASES
34
+
35
+
36
+ if len(_EXAMPLE_CONFLICT_CASES) > 0:
37
+
38
+ def get_name(case):
39
+ model = case.model
40
+ if isinstance(model, torch.nn.Module):
41
+ model = type(model)
42
+ return model.__name__
43
+
44
+ msg = "Error on conflict export case name.\n"
45
+ for case_name, cases in _EXAMPLE_CONFLICT_CASES.items():
46
+ msg += f"Case name {case_name} is associated with multiple cases:\n "
47
+ msg += f"[{','.join(map(get_name, cases))}]\n"
48
+
49
+ raise RuntimeError(msg)
50
+
51
+
52
+ def filter_examples_by_support_level(support_level: SupportLevel):
53
+ return {
54
+ key: val
55
+ for key, val in all_examples().items()
56
+ if val.support_level == support_level
57
+ }
58
+
59
+
60
+ def get_rewrite_cases(case):
61
+ return _EXAMPLE_REWRITE_CASES.get(case.name, [])
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (2.66 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/assume_constant_result.cpython-310.pyc ADDED
Binary file (1.04 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/autograd_function.cpython-310.pyc ADDED
Binary file (1.26 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/class_method.cpython-310.pyc ADDED
Binary file (1.11 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_branch_class_method.cpython-310.pyc ADDED
Binary file (2.21 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nested_function.cpython-310.pyc ADDED
Binary file (2.14 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nonlocal_variables.cpython-310.pyc ADDED
Binary file (2.4 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_closed_over_variable.cpython-310.pyc ADDED
Binary file (1.18 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_operands.cpython-310.pyc ADDED
Binary file (1.38 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/cond_predicate.cpython-310.pyc ADDED
Binary file (1.27 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/constrain_as_size_example.cpython-310.pyc ADDED
Binary file (1.05 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/constrain_as_value_example.cpython-310.pyc ADDED
Binary file (1.09 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/decorator.cpython-310.pyc ADDED
Binary file (1.02 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dictionary.cpython-310.pyc ADDED
Binary file (785 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_assert.cpython-310.pyc ADDED
Binary file (789 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_constructor.cpython-310.pyc ADDED
Binary file (837 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_if_guard.cpython-310.pyc ADDED
Binary file (973 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_map.cpython-310.pyc ADDED
Binary file (959 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_round.cpython-310.pyc ADDED
Binary file (982 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_slicing.cpython-310.pyc ADDED
Binary file (827 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_view.cpython-310.pyc ADDED
Binary file (867 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/fn_with_kwargs.cpython-310.pyc ADDED
Binary file (956 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/list_contains.cpython-310.pyc ADDED
Binary file (885 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/list_unpack.cpython-310.pyc ADDED
Binary file (981 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/model_attr_mutation.cpython-310.pyc ADDED
Binary file (1.27 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/nested_function.cpython-310.pyc ADDED
Binary file (951 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/null_context_manager.cpython-310.pyc ADDED
Binary file (907 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/optional_input.cpython-310.pyc ADDED
Binary file (856 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/pytree_flatten.cpython-310.pyc ADDED
Binary file (805 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/scalar_output.cpython-310.pyc ADDED
Binary file (1.11 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/specialized_attribute.cpython-310.pyc ADDED
Binary file (1.16 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/static_for_loop.cpython-310.pyc ADDED
Binary file (928 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/static_if.cpython-310.pyc ADDED
Binary file (797 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/tensor_setattr.cpython-310.pyc ADDED
Binary file (760 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/type_reflection_method.cpython-310.pyc ADDED
Binary file (1.08 kB). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/unsupported_operator.cpython-310.pyc ADDED
Binary file (851 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/__pycache__/user_input_mutation.cpython-310.pyc ADDED
Binary file (724 Bytes). View file
 
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/assume_constant_result.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+ import torch._dynamo as torchdynamo
4
+
5
+
6
+ class AssumeConstantResult(torch.nn.Module):
7
+ """
8
+ Applying `assume_constant_result` decorator to burn make non-tracable code as constant.
9
+ """
10
+
11
+ @torchdynamo.assume_constant_result
12
+ def get_item(self, y):
13
+ return y.int().item()
14
+
15
+ def forward(self, x, y):
16
+ return x[: self.get_item(y)]
17
+
18
+ example_args = (torch.randn(3, 2), torch.tensor(4))
19
+ tags = {"torch.escape-hatch"}
20
+ model = AssumeConstantResult()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/autograd_function.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ class MyAutogradFunction(torch.autograd.Function):
5
+ @staticmethod
6
+ def forward(ctx, x):
7
+ return x.clone()
8
+
9
+ @staticmethod
10
+ def backward(ctx, grad_output):
11
+ return grad_output + 1
12
+
13
+ class AutogradFunction(torch.nn.Module):
14
+ """
15
+ TorchDynamo does not keep track of backward() on autograd functions. We recommend to
16
+ use `allow_in_graph` to mitigate this problem.
17
+ """
18
+
19
+ def forward(self, x):
20
+ return MyAutogradFunction.apply(x)
21
+
22
+ example_args = (torch.randn(3, 2),)
23
+ model = AutogradFunction()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/class_method.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ class ClassMethod(torch.nn.Module):
5
+ """
6
+ Class methods are inlined during tracing.
7
+ """
8
+
9
+ @classmethod
10
+ def method(cls, x):
11
+ return x + 1
12
+
13
+ def __init__(self) -> None:
14
+ super().__init__()
15
+ self.linear = torch.nn.Linear(4, 2)
16
+
17
+ def forward(self, x):
18
+ x = self.linear(x)
19
+ return self.method(x) * self.__class__.method(x) * type(self).method(x)
20
+
21
+ example_args = (torch.randn(3, 4),)
22
+ model = ClassMethod()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_branch_class_method.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ from functorch.experimental.control_flow import cond
5
+
6
+ class MySubModule(torch.nn.Module):
7
+ def foo(self, x):
8
+ return x.cos()
9
+
10
+ def forward(self, x):
11
+ return self.foo(x)
12
+
13
+ class CondBranchClassMethod(torch.nn.Module):
14
+ """
15
+ The branch functions (`true_fn` and `false_fn`) passed to cond() must follow these rules:
16
+ - both branches must take the same args, which must also match the branch args passed to cond.
17
+ - both branches must return a single tensor
18
+ - returned tensor must have the same tensor metadata, e.g. shape and dtype
19
+ - branch function can be free function, nested function, lambda, class methods
20
+ - branch function can not have closure variables
21
+ - no inplace mutations on inputs or global variables
22
+
23
+
24
+ This example demonstrates using class method in cond().
25
+
26
+ NOTE: If the `pred` is test on a dim with batch size < 2, it will be specialized.
27
+ """
28
+
29
+ def __init__(self) -> None:
30
+ super().__init__()
31
+ self.subm = MySubModule()
32
+
33
+ def bar(self, x):
34
+ return x.sin()
35
+
36
+ def forward(self, x):
37
+ return cond(x.shape[0] <= 2, self.subm.forward, self.bar, [x])
38
+
39
+ example_args = (torch.randn(3),)
40
+ tags = {
41
+ "torch.cond",
42
+ "torch.dynamic-shape",
43
+ }
44
+ model = CondBranchClassMethod()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_closed_over_variable.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ from functorch.experimental.control_flow import cond
5
+
6
+ class CondClosedOverVariable(torch.nn.Module):
7
+ """
8
+ torch.cond() supports branches closed over arbitrary variables.
9
+ """
10
+
11
+ def forward(self, pred, x):
12
+ def true_fn(val):
13
+ return x * 2
14
+
15
+ def false_fn(val):
16
+ return x - 2
17
+
18
+ return cond(pred, true_fn, false_fn, [x + 1])
19
+
20
+ example_args = (torch.tensor(True), torch.randn(3, 2))
21
+ tags = {"torch.cond", "python.closure"}
22
+ model = CondClosedOverVariable()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_operands.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ from torch.export import Dim
5
+
6
+ x = torch.randn(3, 2)
7
+ y = torch.randn(2)
8
+ dim0_x = Dim("dim0_x")
9
+
10
+ class CondOperands(torch.nn.Module):
11
+ """
12
+ The operands passed to cond() must be:
13
+ - a list of tensors
14
+ - match arguments of `true_fn` and `false_fn`
15
+
16
+ NOTE: If the `pred` is test on a dim with batch size < 2, it will be specialized.
17
+ """
18
+
19
+ def forward(self, x, y):
20
+ def true_fn(x, y):
21
+ return x + y
22
+
23
+ def false_fn(x, y):
24
+ return x - y
25
+
26
+ return torch.cond(x.shape[0] > 2, true_fn, false_fn, [x, y])
27
+
28
+ example_args = (x, y)
29
+ tags = {
30
+ "torch.cond",
31
+ "torch.dynamic-shape",
32
+ }
33
+ extra_inputs = (torch.randn(2, 2), torch.randn(2))
34
+ dynamic_shapes = {"x": {0: dim0_x}, "y": None}
35
+ model = CondOperands()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/cond_predicate.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ from functorch.experimental.control_flow import cond
5
+
6
+ class CondPredicate(torch.nn.Module):
7
+ """
8
+ The conditional statement (aka predicate) passed to cond() must be one of the following:
9
+ - torch.Tensor with a single element
10
+ - boolean expression
11
+
12
+ NOTE: If the `pred` is test on a dim with batch size < 2, it will be specialized.
13
+ """
14
+
15
+ def forward(self, x):
16
+ pred = x.dim() > 2 and x.shape[2] > 10
17
+
18
+ return cond(pred, lambda x: x.cos(), lambda y: y.sin(), [x])
19
+
20
+ example_args = (torch.randn(6, 4, 3),)
21
+ tags = {
22
+ "torch.cond",
23
+ "torch.dynamic-shape",
24
+ }
25
+ model = CondPredicate()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/constrain_as_size_example.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+
5
+ class ConstrainAsSizeExample(torch.nn.Module):
6
+ """
7
+ If the value is not known at tracing time, you can provide hint so that we
8
+ can trace further. Please look at torch._check and torch._check_is_size APIs.
9
+ torch._check_is_size is used for values that NEED to be used for constructing
10
+ tensor.
11
+ """
12
+
13
+ def forward(self, x):
14
+ a = x.item()
15
+ torch._check_is_size(a)
16
+ torch._check(a <= 5)
17
+ return torch.zeros((a, 5))
18
+
19
+
20
+ example_args = (torch.tensor(4),)
21
+ tags = {
22
+ "torch.dynamic-value",
23
+ "torch.escape-hatch",
24
+ }
25
+ model = ConstrainAsSizeExample()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/constrain_as_value_example.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+
5
+ class ConstrainAsValueExample(torch.nn.Module):
6
+ """
7
+ If the value is not known at tracing time, you can provide hint so that we
8
+ can trace further. Please look at torch._check and torch._check_is_size APIs.
9
+ torch._check is used for values that don't need to be used for constructing
10
+ tensor.
11
+ """
12
+
13
+ def forward(self, x, y):
14
+ a = x.item()
15
+ torch._check(a >= 0)
16
+ torch._check(a <= 5)
17
+
18
+ if a < 6:
19
+ return y.sin()
20
+ return y.cos()
21
+
22
+
23
+ example_args = (torch.tensor(4), torch.randn(5, 5))
24
+ tags = {
25
+ "torch.dynamic-value",
26
+ "torch.escape-hatch",
27
+ }
28
+ model = ConstrainAsValueExample()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/decorator.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import functools
3
+
4
+ import torch
5
+
6
+ def test_decorator(func):
7
+ @functools.wraps(func)
8
+ def wrapper(*args, **kwargs):
9
+ return func(*args, **kwargs) + 1
10
+
11
+ return wrapper
12
+
13
+ class Decorator(torch.nn.Module):
14
+ """
15
+ Decorators calls are inlined into the exported function during tracing.
16
+ """
17
+
18
+ @test_decorator
19
+ def forward(self, x, y):
20
+ return x + y
21
+
22
+ example_args = (torch.randn(3, 2), torch.randn(3, 2))
23
+ model = Decorator()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/dictionary.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ class Dictionary(torch.nn.Module):
5
+ """
6
+ Dictionary structures are inlined and flattened along tracing.
7
+ """
8
+
9
+ def forward(self, x, y):
10
+ elements = {}
11
+ elements["x2"] = x * x
12
+ y = y * elements["x2"]
13
+ return {"y": y}
14
+
15
+ example_args = (torch.randn(3, 2), torch.tensor(4))
16
+ tags = {"python.data-structure"}
17
+ model = Dictionary()
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/torch/_export/db/examples/dynamic_shape_assert.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mypy: allow-untyped-defs
2
+ import torch
3
+
4
+ class DynamicShapeAssert(torch.nn.Module):
5
+ """
6
+ A basic usage of python assertion.
7
+ """
8
+
9
+ def forward(self, x):
10
+ # assertion with error message
11
+ assert x.shape[0] > 2, f"{x.shape[0]} is greater than 2"
12
+ # assertion without error message
13
+ assert x.shape[0] > 1
14
+ return x
15
+
16
+ example_args = (torch.randn(3, 2),)
17
+ tags = {"python.assert"}
18
+ model = DynamicShapeAssert()