python_code
stringlengths
0
1.02M
repo_name
stringlengths
9
48
file_path
stringlengths
5
114
import caffe2.python.fakelowp.init_shared_libs # noqa import numpy as np from caffe2.python import core, workspace from caffe2.python.onnx.onnxifi import onnxifi_caffe2_net from hypothesis import given, strategies as st, settings from caffe2.python.fakelowp.test_utils import print_test_debug_info import caffe2.python....
pytorch-master
caffe2/contrib/fakelowp/test/test_int8_ops_nnpi.py
# Must happen before importing caffe2.python.* import caffe2.python.fakelowp.init_shared_libs # noqa import datetime import numpy as np from hypothesis import given, settings, example from hypothesis import strategies as st from caffe2.python import core, workspace from caffe2.python.onnx.onnxifi import onnxifi_caffe2...
pytorch-master
caffe2/contrib/fakelowp/test/test_chunking.py
import numpy as np import caffe2.python.fakelowp.init_shared_libs # noqa from caffe2.python import core, workspace from caffe2.python.onnx.onnxifi import onnxifi_caffe2_net from caffe2.python.fakelowp.test_utils import print_test_debug_info import caffe2.python.serialized_test.serialized_test_util as serial import dat...
pytorch-master
caffe2/contrib/fakelowp/test/test_deq_swish_quant_nnpi.py
import numpy as np import unittest import caffe2.python.fakelowp.init_shared_libs # noqa from hypothesis import given, settings from hypothesis import strategies as st from caffe2.proto import caffe2_pb2 from caffe2.python import core from caffe2.python import workspace from caffe2.python.onnx.onnxifi import onnxifi_...
pytorch-master
caffe2/contrib/fakelowp/test/test_fc_nnpi_fp16.py
import unittest # Must happen before importing caffe2.python.* import caffe2.python.fakelowp.init_shared_libs # noqa import datetime import numpy as np from hypothesis import given, settings from hypothesis import strategies as st from caffe2.proto import caffe2_pb2 from caffe2.python import core, workspace from caff...
pytorch-master
caffe2/contrib/fakelowp/test/test_sls_8bit_nnpi_fp32.py
import numpy as np import caffe2.python.fakelowp.init_shared_libs # noqa import datetime from hypothesis import given, settings from hypothesis import strategies as st from caffe2.proto import caffe2_pb2 from caffe2.python import core from caffe2.python import workspace from caffe2.python.onnx.onnxifi import onnxifi_...
pytorch-master
caffe2/contrib/fakelowp/test/test_op_nnpi_fp16.py
import unittest from typing import Dict, Any # Must happen before importing caffe2.python.* import caffe2.python.fakelowp.init_shared_libs # noqa import datetime import numpy as np from hypothesis import given, settings from hypothesis import strategies as st from caffe2.proto import caffe2_pb2 from caffe2.python imp...
pytorch-master
caffe2/contrib/fakelowp/test/test_sls_8bit_nnpi_fp16.py
# Must happen before importing caffe2.python.* import caffe2.python.fakelowp.init_shared_libs # noqa import datetime import numpy as np from caffe2.proto import caffe2_pb2 from caffe2.python import core, workspace from caffe2.python.onnx.onnxifi import onnxifi_caffe2_net import caffe2.python.serialized_test.serialized...
pytorch-master
caffe2/contrib/fakelowp/test/test_int8_quant.py
# Must happen before importing caffe2.python.* import caffe2.python.fakelowp.init_shared_libs # noqa import datetime import numpy as np from hypothesis import given, settings from hypothesis import strategies as st from caffe2.proto import caffe2_pb2 from caffe2.python import core, workspace from caffe2.python.onnx.on...
pytorch-master
caffe2/contrib/fakelowp/test/test_fusions.py
pytorch-master
caffe2/contrib/script/__init__.py
pytorch-master
caffe2/contrib/script/examples/__init__.py
import unittest from caffe2.proto import caffe2_pb2 from caffe2.python import core, dyndep, workspace dyndep.InitOpsLibrary("@/caffe2/caffe2/contrib/prof:cuda_profile_ops") class CudaProfileOpsTest(unittest.TestCase): @unittest.skipIf(workspace.NumCudaDevices() < 1, "Need at least 1 GPU") def test_run(s...
pytorch-master
caffe2/contrib/prof/cuda_profile_ops_test.py
pytorch-master
caffe2/contrib/prof/__init__.py
pytorch-master
caffe2/contrib/tensorboard/__init__.py
from builtins import bytes import copy import logging import os from caffe2.proto import caffe2_pb2 from caffe2.python import core, workspace try: # tensorboard>=1.14.0 from tensorboard.compat.proto import tensor_shape_pb2 from tensorboard.compat.proto.node_def_pb2 import NodeDef from tensorboard...
pytorch-master
caffe2/contrib/tensorboard/tensorboard_exporter.py
import click.testing import numpy as np import os import tempfile import unittest from caffe2.python import brew, core, model_helper import caffe2.contrib.tensorboard.tensorboard as tb import caffe2.contrib.tensorboard.tensorboard_exporter as tb_exporter try: # tensorboard>=1.14.0 from tensorboard.compat...
pytorch-master
caffe2/contrib/tensorboard/tensorboard_test.py
import click import collections import logging import numpy as np import os from caffe2.proto import caffe2_pb2 from caffe2.python import core import caffe2.contrib.tensorboard.tensorboard_exporter as tb_exporter try: # tensorboard>=1.14.0 from tensorboard.compat.proto.summary_pb2 import Summary, Histogr...
pytorch-master
caffe2/contrib/tensorboard/tensorboard.py
import unittest from caffe2.proto import caffe2_pb2 import caffe2.python.cnn as cnn import caffe2.python.core as core import caffe2.contrib.tensorboard.tensorboard_exporter as tb EXPECTED = """ node { name: "conv1/XavierFill" op: "XavierFill" device: "/gpu:0" attr { key: "_output_shapes" value { ...
pytorch-master
caffe2/contrib/tensorboard/tensorboard_exporter_test.py
#!/bin/env python3 # Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by appl...
pytorch-master
caffe2/contrib/aten/gen_op.py
from caffe2.python import core from hypothesis import given import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np class TestATen(hu.HypothesisTestCase): @given(inputs=hu.tensors(n=2), **hu.gcs) def test_add(self, inputs, gc, dc): op = core.CreateOperat...
pytorch-master
caffe2/contrib/aten/aten_test.py
pytorch-master
caffe2/contrib/aten/__init__.py
pytorch-master
caffe2/contrib/aten/docs/__init__.py
import tempfile import numpy as np from torch import nn from torch.autograd import Variable, Function import torch.onnx import onnx import caffe2.python.onnx.backend class MyFunction(Function): @staticmethod def forward(ctx, x, y): return x * x + y @staticmethod def symbolic(graph, x, y): ...
pytorch-master
caffe2/contrib/aten/docs/sample.py
pytorch-master
caffe2/quantization/__init__.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given dyndep.InitOpsLibrary("//ca...
pytorch-master
caffe2/quantization/server/relu_dnnlowp_op_test.py
# Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed...
pytorch-master
caffe2/quantization/server/compute_equalization_scale_test.py
import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_omp_num_th...
pytorch-master
caffe2/quantization/server/batch_permutation_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given dyndep.InitOpsLibrary("//ca...
pytorch-master
caffe2/quantization/server/elementwise_add_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import ( avoid_vpmaddubsw_ove...
pytorch-master
caffe2/quantization/server/fully_connected_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import assume, given dyndep.InitOpsLibra...
pytorch-master
caffe2/quantization/server/pool_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, utils, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_res...
pytorch-master
caffe2/quantization/server/group_norm_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given dyndep.InitOpsLibrary("//ca...
pytorch-master
caffe2/quantization/server/dequantize_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st from caffe2.python import core, dyndep, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import ( check_quantized_results_close, gene...
pytorch-master
caffe2/quantization/server/conv_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_...
pytorch-master
caffe2/quantization/server/fully_connected_fp16_test.py
import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_omp_num_th...
pytorch-master
caffe2/quantization/server/resize_nearest_3d_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st from caffe2.python import core, dyndep, workspace from caffe2.python.fb import hardcode_scale_zp # type: ignore[import] from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server....
pytorch-master
caffe2/quantization/server/conv_groupwise_dnnlowp_op_test.py
pytorch-master
caffe2/quantization/server/__init__.py
import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_omp_num_th...
pytorch-master
caffe2/quantization/server/resize_nearest_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given dyndep.InitOpsLibrary("//ca...
pytorch-master
caffe2/quantization/server/gather_dnnlowp_op_test.py
import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, utils, workspace from hypothesis import given, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_omp...
pytorch-master
caffe2/quantization/server/channel_shuffle_dnnlowp_op_test.py
import collections from itertools import product import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils imp...
pytorch-master
caffe2/quantization/server/batch_matmul_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given dyndep.InitOpsLibrary("//ca...
pytorch-master
caffe2/quantization/server/elementwise_sum_dnnlowp_op_test.py
import collections import numpy as np from caffe2.python import utils, workspace from caffe2.quantization.server import dnnlowp_pybind11 from hypothesis import assume # This function asserts quantized results (output[1:]) are close enough to # floating point results (output[0]). # The error bound is derived based ...
pytorch-master
caffe2/quantization/server/dnnlowp_test_utils.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import ( check_quantized_resu...
pytorch-master
caffe2/quantization/server/fully_connected_dnnlowp_acc16_op_test.py
# Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed...
pytorch-master
caffe2/quantization/server/int8_gen_quant_params_min_max_test.py
import copy import logging from collections import defaultdict import numpy as np from caffe2.python import core, utils from caffe2.python.fb import hardcode_scale_zp # type: ignore[import] logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s...
pytorch-master
caffe2/quantization/server/utils.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", ...
pytorch-master
caffe2/quantization/server/tanh_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given, settings dyndep.InitOpsLib...
pytorch-master
caffe2/quantization/server/elementwise_mul_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st from caffe2.python import core, dyndep, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import ( check_quantized_results_close, gene...
pytorch-master
caffe2/quantization/server/conv_depthwise_dnnlowp_op_test.py
# Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed...
pytorch-master
caffe2/quantization/server/int8_quant_scheme_blob_fill_test.py
import numpy as np from caffe2.python import core, workspace from caffe2.quantization.server import dnnlowp_pybind11 # type: ignore[attr-defined] net = core.Net("test_net") X = np.array([[1, 2], [3, 4]]).astype(np.float32) W = np.array([[5, 6], [7, 8]]).astype(np.float32) b = np.array([0, 1]).astype(np.float32) ...
pytorch-master
caffe2/quantization/server/observer_test.py
import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server import dnnlowp_pybind11 from hypothesis import given, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_op...
pytorch-master
caffe2/quantization/server/quantize_dnnlowp_op_test.py
# Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed...
pytorch-master
caffe2/quantization/server/int8_gen_quant_params_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import ( avoid_vpmaddubsw_ove...
pytorch-master
caffe2/quantization/server/fully_connected_rowwise_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, utils, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_res...
pytorch-master
caffe2/quantization/server/spatial_batch_norm_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given dyndep.InitOpsLibrary("//ca...
pytorch-master
caffe2/quantization/server/concat_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, utils, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import ( check_quantiz...
pytorch-master
caffe2/quantization/server/conv_dnnlowp_acc16_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", ...
pytorch-master
caffe2/quantization/server/lstm_unit_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, utils, workspace from caffe2.quantization.server import utils as dnnlowp_utils from caffe2.quantization.server.dnnlowp_test_utils import ( check_quantiz...
pytorch-master
caffe2/quantization/server/conv_groupwise_dnnlowp_acc16_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_...
pytorch-master
caffe2/quantization/server/sigmoid_dnnlowp_op_test.py
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import given dyndep.InitOpsLibrary("//ca...
pytorch-master
caffe2/quantization/server/elementwise_linear_dnnlowp_op_test.py
"""Adds docstrings to Storage functions""" import torch._C from torch._C import _add_docstr as add_docstr storage_classes = [ "StorageBase", ] def add_docstr_all(method, docstr): for cls_name in storage_classes: cls = getattr(torch._C, cls_name) try: add_docstr(getattr(cls, meth...
pytorch-master
torch/_storage_docs.py
from typing import List, Optional, Union import torch import torch._prims_common as utils from torch import Tensor from torch._prims_common import ( check, corresponding_complex_dtype, corresponding_real_dtype, elementwise_dtypes, ELEMENTWISE_TYPE_PROMOTION_KIND, ) from torch._prims_common.wrapper...
pytorch-master
torch/_meta_registrations.py
from ._ops import OpOverload from typing import Set import traceback import torch __all__ = ['Library', 'impl', 'define'] # Set containing the combination of (namespace, operator, DispatchKey) for which a new kernel has been registered # The keys in the set are of the form `namespace + "/" + op_name + "/" + dispatch_...
pytorch-master
torch/library.py
""" The weak_script annotation needs to be here instead of inside torch/jit/ so it can be used in other places in torch/ (namely torch.nn) without running into circular dependency problems """ import ast import builtins import collections import contextlib import enum import inspect import io import pickle import sys ...
pytorch-master
torch/_jit_internal.py
import torch import inspect __all__ = [] # error: Module has no attribute "_return_types" return_types = torch._C._return_types # type: ignore[attr-defined] def pytree_register_structseq(cls): def structseq_flatten(structseq): return list(structseq), None def structseq_unflatten(values, context): ...
pytorch-master
torch/return_types.py
# -*- coding: utf-8 -*- """Adds docstrings to functions defined in the torch._C""" import re import torch._C from torch._C import _add_docstr as add_docstr def parse_kwargs(desc): """Maps a description of args to a dictionary of {argname: description}. Input: (' weight (Tensor): a weight tensor\n...
pytorch-master
torch/_torch_docs.py
import contextlib import ctypes import sys import types import torch._C import torch.jit from torch import _utils_internal # Query `hasattr` only once. _SET_GLOBAL_FLAGS = hasattr(sys, "getdlopenflags") and hasattr(sys, "setdlopenflags") @contextlib.contextmanager def dl_open_guard(): """ Context manager t...
pytorch-master
torch/_ops.py
import os import sys import tempfile # this arbitrary-looking assortment of functionality is provided here # to have a central place for overrideable behavior. The motivating # use is the FB build environment, where this source file is replaced # by an equivalent. if sys.executable == "torch_deploy": # __file__ ...
pytorch-master
torch/_utils_internal.py
import torch from typing import Optional class SobolEngine(object): r""" The :class:`torch.quasirandom.SobolEngine` is an engine for generating (scrambled) Sobol sequences. Sobol sequences are an example of low discrepancy quasi-random sequences. This implementation of an engine for Sobol sequenc...
pytorch-master
torch/quasirandom.py
from typing import Any, Iterable from .version import __version__ as internal_version __all__ = ['TorchVersion', 'Version', 'InvalidVersion'] class _LazyImport: """Wraps around classes lazy imported from packaging.version Output of the function v in following snippets are identical: from packaging.vers...
pytorch-master
torch/torch_version.py
""" This makes the functions in torch._C._VariableFunctions available as torch._VF.<funcname> without mypy being able to find them. A subset of those functions are mapped to ATen functions in torch/jit/_builtins.py See https://github.com/pytorch/pytorch/issues/21478 for the reason for introducing torch._VF """ i...
pytorch-master
torch/_VF.py
"""Adds docstrings to Tensor functions""" import torch._C from torch._C import _add_docstr as add_docstr from ._torch_docs import parse_kwargs, reproducibility_notes def add_docstr_all(method, docstr): add_docstr(getattr(torch._C._TensorBase, method), docstr) common_args = parse_kwargs( """ memory_form...
pytorch-master
torch/_tensor_docs.py
# Copyright (c) 2010-2017 Benjamin Peterson # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publi...
pytorch-master
torch/_six.py
r""" The torch package contains data structures for multi-dimensional tensors and defines mathematical operations over these tensors. Additionally, it provides many utilities for efficient serializing of Tensors and arbitrary types, and other useful utilities. It has a CUDA counterpart, that enables you to run your t...
pytorch-master
torch/__init__.py
""" Python implementation of ``__torch_function__`` While most of the torch API and handling for ``__torch_function__`` happens at the C++ level, some of the torch API is written in Python so we need python-level handling for ``__torch_function__`` overrides as well. The main developer-facing functionality in this fil...
pytorch-master
torch/overrides.py
from collections import OrderedDict """ This file contains helper functions that implement experimental functionality for named tensors in python. All of these are experimental, unstable, and subject to change or deletion. """ def check_serializing_named_tensor(tensor): if tensor.has_names(): raise Runti...
pytorch-master
torch/_namedtensor_internals.py
import torch from typing import Any, List, Sequence, Tuple, Union import builtins # Convenience aliases for common composite types that we need # to talk about in PyTorch _TensorOrTensors = Union[torch.Tensor, Sequence[torch.Tensor]] # In some cases, these basic types are shadowed by corresponding # top-level value...
pytorch-master
torch/types.py
"""Various linear algebra utility methods for internal use. """ from typing import Optional, Tuple import torch from torch import Tensor def is_sparse(A): """Check if tensor A is a sparse tensor""" if isinstance(A, torch.Tensor): return A.layout == torch.sparse_coo error_str = "expected Tensor...
pytorch-master
torch/_linalg_utils.py
import torch def show(): """ Return a human-readable string with descriptions of the configuration of PyTorch. """ return torch._C._show_config() # TODO: In principle, we could provide more structured version/config # information here. For now only CXX_FLAGS is exposed, as Timer # uses them. def...
pytorch-master
torch/__config__.py
import copyreg import enum import functools import warnings from collections import OrderedDict from copy import deepcopy from numbers import Number from typing import Any, Dict, Optional, Tuple, Union import torch import torch._C as _C import torch.utils.hooks as hooks from torch._namedtensor_internals import ( c...
pytorch-master
torch/_tensor.py
import contextlib from typing import Generator import warnings from torch._C import default_generator import torch def set_rng_state(new_state: torch.Tensor) -> None: r"""Sets the random number generator state. .. note: This function only works for CPU. For CUDA, please use torch.manual_seed(se...
pytorch-master
torch/random.py
import errno import hashlib import json import os import re import shutil import sys import tempfile import torch import warnings import zipfile from pathlib import Path from typing import Callable, Dict, Optional, Union, Any from urllib.error import HTTPError from urllib.request import urlopen, Request from urllib.par...
pytorch-master
torch/hub.py
import math from typing import Optional import torch from torch._six import inf class __PrinterOptions(object): precision: int = 4 threshold: float = 1000 edgeitems: int = 3 linewidth: int = 80 sci_mode: Optional[bool] = None PRINT_OPTS = __PrinterOptions() # We could use **kwargs, but this w...
pytorch-master
torch/_tensor_str.py
import ast import functools import inspect from textwrap import dedent from typing import Any, List, NamedTuple, Optional, Tuple from torch._C import ErrorReport from torch._C._jit_tree_views import SourceRangeFactory def get_source_lines_and_file( obj: Any, error_msg: Optional[str] = None, ) -> Tuple[List[s...
pytorch-master
torch/_sources.py
import functools import warnings from typing import Any, Callable, List, Optional, Tuple, Union import torch from torch import Tensor from torch.utils._pytree import _broadcast_to_and_flatten, tree_flatten, tree_unflatten in_dims_t = Union[int, Tuple] out_dims_t = Union[int, Tuple[int, ...]] # Checks that all args-t...
pytorch-master
torch/_vmap_internals.py
from typing import ( List, Tuple, Optional, Union, Any, Sequence, TYPE_CHECKING ) import torch from torch._C import _add_docstr import torch.nn.functional as F from ._lowrank import svd_lowrank, pca_lowrank from .overrides import ( has_torch_function, has_torch_function_unary, has_torch_function_variadic, ...
pytorch-master
torch/functional.py
"""Implement various linear algebra algorithms for low rank matrices. """ __all__ = ["svd_lowrank", "pca_lowrank"] from typing import Optional, Tuple import torch from torch import Tensor from . import _linalg_utils as _utils from .overrides import handle_torch_function, has_torch_function def get_approximate_basi...
pytorch-master
torch/_lowrank.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (c) 2005-2010 ActiveState Software Inc. # Copyright (c) 2013 Eddy Petrișor # flake8: noqa """ This file is directly from https://github.com/ActiveState/appdirs/blob/3fe6a83776843a46f20c2e5587afcffe05e03b39/appdirs.py The license of https://github.com/ActiveS...
pytorch-master
torch/_appdirs.py
import io import torch from ._utils import _type, _cuda from torch.types import Storage from typing import Any, TypeVar, Type, Union, cast import copy import collections from functools import lru_cache try: import numpy as np HAS_NUMPY = True except ModuleNotFoundError: np = None # type: ignore[assignment...
pytorch-master
torch/storage.py
"""Locally Optimal Block Preconditioned Conjugate Gradient methods. """ # Author: Pearu Peterson # Created: February 2020 from typing import Dict, Optional, Tuple import torch from torch import Tensor from . import _linalg_utils as _utils from .overrides import handle_torch_function, has_torch_function __all__ = ["...
pytorch-master
torch/_lobpcg.py
""" This global flag controls whether to assign new tensors to the parameters instead of changing the existing parameters in-place when converting an `nn.Module` using the following methods: 1. `module.cuda()` / `.cpu()` (for moving `module` between devices) 2. `module.float()` / `.double()` / `.half()` (for converting...
pytorch-master
torch/__future__.py
import io import torch from torch.package import Importer, OrderedImporter, PackageImporter, sys_importer from torch.package._package_pickler import create_pickler from torch.package._package_unpickler import PackageUnpickler from torch.serialization import _maybe_decode_ascii def _save_storages(importer, obj): ...
pytorch-master
torch/_deploy.py
import re import torch._C as C """ PythonDispatcher class is a thin python-binding to C++ dispatcher and it is designed to show how dispatcher precompute works. In particular, it shows for a certain op `foo`, what the computed dispatch table looks like after user register their kernels to certains dispatch keys. In...
pytorch-master
torch/_python_dispatcher.py
import types import torch._C class _ClassNamespace(types.ModuleType): def __init__(self, name): super(_ClassNamespace, self).__init__("torch.classes" + name) self.name = name def __getattr__(self, attr): proxy = torch._C._get_custom_class_python_wrapper(self.name, attr) if pr...
pytorch-master
torch/_classes.py
import difflib import os import io import shutil import struct import sys import torch import tarfile import tempfile import warnings from contextlib import closing, contextmanager from ._utils import _import_dotted_name from ._six import string_classes as _string_classes from torch._sources import get_source_lines_and...
pytorch-master
torch/serialization.py
import sys import traceback import warnings from collections import defaultdict from typing import Any, DefaultDict, List, Optional import torch def _type(self, dtype=None, non_blocking=False, **kwargs): """Returns the type if `dtype` is not provided, else casts this object to the specified type. If thi...
pytorch-master
torch/_utils.py
from copy import deepcopy from dataclasses import dataclass from functools import lru_cache from warnings import warn import torch import torch.overrides from torch._prims_common import getnvFuserDtype, Number from torch.fx import GraphModule from torch.fx.passes.infra.partitioner import CapabilityBasedPartitioner fr...
pytorch-master
torch/_prims/nvfuser_executor.py
import contextlib import itertools import math import operator import weakref from enum import Enum from functools import partial, reduce from typing import Any, Callable, List, Optional, Sequence, Tuple, Type, Union import torch import torch._prims_common as utils import torch.library from torch import Tensor, Typed...
pytorch-master
torch/_prims/__init__.py
import functools from contextlib import nullcontext from typing import Any, Callable, Dict, Sequence import torch import torch._prims import torch._refs import torch._refs.nn import torch._refs.nn.functional import torch._refs.special import torch.overrides from torch._prims_common import torch_function_passthrough...
pytorch-master
torch/_prims/context.py