#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # pyre-strict from typing import TypeVar import torch from pyre_extensions import Generic, ListVariadic from torch import cat, mm, randn, unsqueeze # noqa from .nn import Linear # noqa # New Variadic Type Variadic, a place-holder for an unknown number of # variables Shape = ListVariadic("Shape") # ad-hoc dtypes for testing purpose DType = TypeVar("DType", int, float) int32 = int float32 = float # Minimal Tensor stub class Tensor(Generic[DType, Shape], torch.Tensor): pass
# Copyright (c) 2016-present, Facebook, Inc. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import ast import logging from logging import Logger from typing import Callable # pyre-fixme[21]: Could not find name `ListVariadic` in `pyre_extensions`. from pyre_extensions import ListVariadic from pyre_extensions.type_variable_operators import Concatenate Ts = ListVariadic("Ts") LOG: Logger = logging.getLogger(__name__) class UnstableAST(Exception): pass def check_stable(input: str, transformed: str) -> None: parsed_original = ast.parse(input) try: parsed_transformed = ast.parse(transformed) if ast.dump(parsed_original) != ast.dump(parsed_transformed): raise UnstableAST("ASTs differ")
# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import ast import logging from logging import Logger from typing import Callable from pyre_extensions import ListVariadic from pyre_extensions.type_variable_operators import Concatenate Ts: object = ListVariadic("Ts") LOG: Logger = logging.getLogger(__name__) class UnstableAST(Exception): pass def check_stable(input: str, transformed: str) -> None: parsed_original = ast.parse(input) try: parsed_transformed = ast.parse(transformed) if ast.dump(parsed_original) != ast.dump(parsed_transformed): raise UnstableAST("ASTs differ") except SyntaxError: raise UnstableAST("Could not parse transformed AST")