Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lib/python3.12/site-packages/torch/_export/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/converter.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/error.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/non_strict_utils.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/pass_base.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/tools.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/utils.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/verifier.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/__pycache__/wrappers.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/__init__.pyAdded+5
- lib/python3.12/site-packages/torch/_export/db/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/__pycache__/case.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/__pycache__/gen_example.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/__pycache__/logging.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/case.pyAdded+174
- lib/python3.12/site-packages/torch/_export/db/examples/__init__.pyAdded+61
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/assume_constant_result.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/autograd_function.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/class_method.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_branch_class_method.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nested_function.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nonlocal_variables.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_closed_over_variable.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_operands.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_predicate.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/constrain_as_size_example.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/constrain_as_value_example.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/decorator.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dictionary.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_assert.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_constructor.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_if_guard.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_map.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_round.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_slicing.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_view.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/fn_with_kwargs.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/list_contains.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/list_unpack.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/model_attr_mutation.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/nested_function.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/null_context_manager.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/optional_input.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/pytree_flatten.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/scalar_output.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/specialized_attribute.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/static_for_loop.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/static_if.cpython-312.pycAdded
- lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/tensor_setattr.cpython-312.pycAdded
12345# Copyright (c) Facebook, Inc. and its affiliates.# All rights reserved.## This source code is licensed under the BSD-style license found in the# LICENSE file in the root directory of this source tree.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174# mypy: allow-untyped-defsimport inspectimport reimport stringfrom dataclasses import dataclass, fieldfrom enum import Enumfrom typing import Any, Dict, List, Optional, Set, Tuplefrom types import ModuleType
import torch
_TAGS: Dict[str, Dict[str, Any]] = { "torch": { "cond": {}, "dynamic-shape": {}, "escape-hatch": {}, "map": {}, "dynamic-value": {}, "operator": {}, "mutation": {}, }, "python": { "assert": {}, "builtin": {}, "closure": {}, "context-manager": {}, "control-flow": {}, "data-structure": {}, "standard-library": {}, "object-model": {}, },}
class SupportLevel(Enum): """ Indicates at what stage the feature used in the example is handled in export. """
SUPPORTED = 1 NOT_SUPPORTED_YET = 0
ArgsType = Tuple[Any, ...]
def check_inputs_type(args, kwargs): if not isinstance(args, tuple): raise ValueError( f"Expecting args type to be a tuple, got: {type(args)}" ) if not isinstance(kwargs, dict): raise ValueError( f"Expecting kwargs type to be a dict, got: {type(kwargs)}" ) for key in kwargs: if not isinstance(key, str): raise ValueError( f"Expecting kwargs keys to be a string, got: {type(key)}" )
def _validate_tag(tag: str): parts = tag.split(".") t = _TAGS for part in parts: assert set(part) <= set( string.ascii_lowercase + "-" ), f"Tag contains invalid characters: {part}" if part in t: t = t[part] else: raise ValueError(f"Tag {tag} is not found in registered tags.")
@dataclass(frozen=True)class ExportCase: example_args: ArgsType description: str # A description of the use case. model: torch.nn.Module name: str example_kwargs: Dict[str, Any] = field(default_factory=dict) extra_args: Optional[ArgsType] = None # For testing graph generalization. # Tags associated with the use case. (e.g dynamic-shape, escape-hatch) tags: Set[str] = field(default_factory=set) support_level: SupportLevel = SupportLevel.SUPPORTED dynamic_shapes: Optional[Dict[str, Any]] = None
def __post_init__(self): check_inputs_type(self.example_args, self.example_kwargs) if self.extra_args is not None: check_inputs_type(self.extra_args, {})
for tag in self.tags: _validate_tag(tag)
if not isinstance(self.description, str) or len(self.description) == 0: raise ValueError(f'Invalid description: "{self.description}"')
_EXAMPLE_CASES: Dict[str, ExportCase] = {}_MODULES: Set[ModuleType] = set()_EXAMPLE_CONFLICT_CASES: Dict[str, List[ExportCase]] = {}_EXAMPLE_REWRITE_CASES: Dict[str, List[ExportCase]] = {}
def register_db_case(case: ExportCase) -> None: """ Registers a user provided ExportCase into example bank. """ if case.name in _EXAMPLE_CASES: if case.name not in _EXAMPLE_CONFLICT_CASES: _EXAMPLE_CONFLICT_CASES[case.name] = [_EXAMPLE_CASES[case.name]] _EXAMPLE_CONFLICT_CASES[case.name].append(case) return
_EXAMPLE_CASES[case.name] = case
def to_snake_case(name): name = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name) return re.sub("([a-z0-9])([A-Z])", r"\1_\2", name).lower()
def _make_export_case(m, name, configs): if not isinstance(m, torch.nn.Module): raise TypeError("Export case class should be a torch.nn.Module.")
if "description" not in configs: # Fallback to docstring if description is missing. assert ( m.__doc__ is not None ), f"Could not find description or docstring for export case: {m}" configs = {**configs, "description": m.__doc__} return ExportCase(**{**configs, "model": m, "name": name})
def export_case(**kwargs): """ Decorator for registering a user provided case into example bank. """
def wrapper(m): configs = kwargs module = inspect.getmodule(m) if module in _MODULES: raise RuntimeError("export_case should only be used once per example file.")
assert module is not None _MODULES.add(module) module_name = module.__name__.split(".")[-1] case = _make_export_case(m, module_name, configs) register_db_case(case) return case
return wrapper
def export_rewrite_case(**kwargs): def wrapper(m): configs = kwargs
parent = configs.pop("parent") assert isinstance(parent, ExportCase) key = parent.name if key not in _EXAMPLE_REWRITE_CASES: _EXAMPLE_REWRITE_CASES[key] = []
configs["example_args"] = parent.example_args case = _make_export_case(m, to_snake_case(m.__name__), configs) _EXAMPLE_REWRITE_CASES[key].append(case) return case
return wrapper12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061# mypy: allow-untyped-defsimport dataclassesimport globimport inspectfrom os.path import basename, dirname, isfile, join
import torchfrom torch._export.db.case import ( _EXAMPLE_CASES, _EXAMPLE_CONFLICT_CASES, _EXAMPLE_REWRITE_CASES, SupportLevel, export_case, ExportCase,)
def _collect_examples(): case_names = glob.glob(join(dirname(__file__), "*.py")) case_names = [ basename(f)[:-3] for f in case_names if isfile(f) and not f.endswith("__init__.py") ]
case_fields = {f.name for f in dataclasses.fields(ExportCase)} for case_name in case_names: case = __import__(case_name, globals(), locals(), [], 1) variables = [name for name in dir(case) if name in case_fields] export_case(**{v: getattr(case, v) for v in variables})(case.model)
_collect_examples()
def all_examples(): return _EXAMPLE_CASES
if len(_EXAMPLE_CONFLICT_CASES) > 0:
def get_name(case): model = case.model if isinstance(model, torch.nn.Module): model = type(model) return model.__name__
msg = "Error on conflict export case name.\n" for case_name, cases in _EXAMPLE_CONFLICT_CASES.items(): msg += f"Case name {case_name} is associated with multiple cases:\n " msg += f"[{','.join(map(get_name, cases))}]\n"
raise RuntimeError(msg)
def filter_examples_by_support_level(support_level: SupportLevel): return { key: val for key, val in all_examples().items() if val.support_level == support_level }
def get_rewrite_cases(case): return _EXAMPLE_REWRITE_CASES.get(case.name, [])lib/python3.12/site-packages/torch/_export/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/converter.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/error.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/non_strict_utils.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/pass_base.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/tools.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/utils.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/verifier.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/__pycache__/wrappers.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/__init__.pyAdded+5
lib/python3.12/site-packages/torch/_export/db/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/__pycache__/case.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/__pycache__/gen_example.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/__pycache__/logging.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/case.pyAdded+174
lib/python3.12/site-packages/torch/_export/db/examples/__init__.pyAdded+61
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/assume_constant_result.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/autograd_function.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/class_method.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_branch_class_method.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nested_function.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_branch_nonlocal_variables.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_closed_over_variable.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_operands.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/cond_predicate.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/constrain_as_size_example.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/constrain_as_value_example.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/decorator.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dictionary.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_assert.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_constructor.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_if_guard.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_map.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_round.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_slicing.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/dynamic_shape_view.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/fn_with_kwargs.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/list_contains.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/list_unpack.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/model_attr_mutation.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/nested_function.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/null_context_manager.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/optional_input.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/pytree_flatten.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/scalar_output.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/specialized_attribute.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/static_for_loop.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/static_if.cpython-312.pycAdded
lib/python3.12/site-packages/torch/_export/db/examples/__pycache__/tensor_setattr.cpython-312.pycAdded