from collections import defaultdict import torch <del> try: FileNotFoundError except NameError: # py2.7 FileNotFoundError = IOError </del> <ins> from torch._six import FileNotFoundError </ins> class range(object):


self.assertEqual(output.names, ['N', 'H', 'W', 'C']) self.assertEqual(output.shape, [3, 5, 1, 2]) <ins> @unittest.skip("Not implemented yet") </ins> def test_align_tensors_two_inputs(self): def _test(tensor_namedshape, align_names, expected_sizes, expected_error): tensor_names, tensor_sizes = tensor_namedshape


#define THC_GENERIC_FILE "generic/THCTensorIndex.cu" #else <ins> // Check tensor dimensions for index operations, and return the slice size. // src can be nullptr in case of indexFill: in that case it is ignored. static ptrdiff_t THCTensor_(getSliceSize)(THCState *state, THCTensor *dst, int dim, THCudaLongTensor *index, THCTensor *src) { int dstDims = THCTensor_(nDimension)(state, dst); int srcDims = (src == nullptr) ? dstDims : THCTensor_(nDimension)(state, src); THArgCheck(THCudaLongTensor_nDimension(state, index) == 1, 4, "expecting vector of indices"); THArgCheck(dim >= 0 && dim < dstDims, 2, "Indexing dim is out of bounds"); ptrdiff_t dstSliceSize = 1; for (int d = 0; d < dstDims; d++) { if (d != dim) { dstSliceSize *= dst->size[d]; } } if (src == nullptr) return dstSliceSize; THArgCheck(dim < srcDims, 3, "Indexing dim is out of bounds"); THArgCheck(THCudaLongTensor_nElement(state, index) == src->size[dim], 4, "length of src.size[dim] is not equal to length of indices"); ptrdiff_t srcSliceSize = 1; bool mismatch = false; if (dstDims != srcDims) mismatch = true; for (int d = 0; d < srcDims; d++) { if (d != dim) { srcSliceSize *= src->size[d]; if (!mismatch && dst->size[d] != src->size[d]) mismatch = true; } } THArgCheck(dstSliceSize == srcSliceSize, 2, "Source/destination tensor have different slice sizes (%ld vs %ld)", dstSliceSize, srcSliceSize); if (mismatch) { static bool warningShown = false; if (!warningShown) { warningShown = true; fprintf(stderr, "Warning: source/destination slices have same size but different " "shape for an index operation.  This behavior is deprecated.n"); } } return dstSliceSize; } </ins> void THCTensor_(indexCopy_long)(THCState *state, THCTensor *dst, int dim, THLongTensor *indices, THCTensor *src) { THCAssertSameGPU(THCTensor_(checkGPU)(state, 2, dst, src));


.. math:: f(X) = sqrt[p]{sum_{x in X} x^{p}} <del> - At p = infinity, one gets Max Pooling - At p = 1, one gets Average Pooling </del> <ins> - At p = infinity, one gets Max Pooling - At p = 1, one gets Sum Pooling (which is proportional to Average Pooling) </ins> The parameters :attr:`kernel_size`, :attr:`stride` can either be:


} #if CUDA_VERSION >= 9010 <del> void THCudaBlas_HgemmStridedBatched(THCState *state, char transa, char transb, long m, long n, long k, half alpha, const half *a, long lda, long strideA, const half *b, long ldb, long strideB, half beta, half *c, long ldc, long strideC, long batchCount) </del> <ins> void THCudaBlas_HgemmStridedBatched(THCState *state, char transa, char transb, int64_t m, int64_t n, int64_t k, half alpha, const half *a, int64_t lda, int64_t strideA, const half *b, int64_t ldb, int64_t strideB, half beta, half *c, int64_t ldc, int64_t strideC, int64_t batchCount) </ins> { if( (m >= INT_MAX) || (n >= INT_MAX) || (k >= INT_MAX) || (lda >= INT_MAX)  || (ldb >= INT_MAX) || (ldc >= INT_MAX) || (batchCount >= INT_MAX) )


END_HANDLE_TH_ERRORS } <ins> PyObject * THCPModule_getLibPath(PyObject *_unused) { #define _STR(x) #x #define STR(x) _STR(x) #if PY_MAJOR_VERSION == 2 return PyString_FromString(STR(CUDA_LIB_PATH)); #else return PyUnicode_FromString(STR(CUDA_LIB_PATH)); #endif #undef STR #undef _STR } </ins> //////////////////////////////////////////////////////////////////////////////// // Cuda module initialization ////////////////////////////////////////////////////////////////////////////////


def backward(self, grad_output): # TODO: not sure if this clone is necessary <del> return grad_output.clone().view(self.input_size) </del> <ins> return grad_output.contiguous().view(self.input_size) </ins> class Expand(Function):


static inline __host__ __device__  uint8_t mul(uint8_t a, uint8_t b) { return a * b; } static inline __host__ __device__  uint8_t sub(uint8_t a, uint8_t b) { return a - b; } static inline __host__ __device__  uint8_t div(uint8_t a, uint8_t b) { return a / b; } <del> static inline __host__ __device__  uint8_t abs(uint8_t a) { return abs(a); } </del> <ins> static inline __host__ __device__  uint8_t abs(uint8_t a) { return a; } </ins> }; template <>


import traceback import os import time <del> from torch._six import string_classes, int_classes </del> <ins> from torch._six import string_classes, int_classes, FileNotFoundError </ins> IS_WINDOWS = sys.platform == "win32" if IS_WINDOWS:


#endif #if CUDA_VERSION >= 9010 <del> void THCudaBlas_HgemmStridedBatched(THCState *state, char transa, char transb, long m, long n, long k, half alpha, const half *a, long lda, long strideA, const half *b, long ldb, long strideB, half beta, half *c, long ldc, long strideC, long batchCount); </del> <ins> void THCudaBlas_HgemmStridedBatched(THCState *state, char transa, char transb, int64_t m, int64_t n, int64_t k, half alpha, const half *a, int64_t lda, int64_t strideA, const half *b, int64_t ldb, int64_t strideB, half beta, half *c, int64_t ldc, int64_t strideC, int64_t batchCount); </ins> #endif /* Inverse */


// So we'll convert all Numpy tensors of 0 elements to empty Torch tensors. if (PyArray_SIZE(array) != 0) { auto ndim = PyArray_NDIM(array); <ins> size_t storage_size = 1; </ins> THLongStoragePtr sizes = THLongStorage_newWithSize(ndim); long *sizes_data = sizes->data; for (int i = 0; i < ndim; ++i) {


import os.path import torch.nn.modules.activation import torch.autograd <ins> import matplotlib matplotlib.use('Agg') </ins> import pylab


self.assertEqual(output.shape, [3, 5, 1, 2]) # All input dimensions must be named <del> with self.assertRaisesRegex(RuntimeError, "All input dims must be named"): </del> <ins> with self.assertRaisesRegex(RuntimeError, "All input dims must be named. Found unnamed dim at index 0"): </ins> create('None:2,C:3').align_to('N', 'C') # not enough names


dims = THCudaLongTensor_nDimension(state, indices); THArgCheck(dims <= MAX_CUTORCH_DIMS, 4, CUTORCH_DIM_WARNING); <del> ptrdiff_t numIndices = THCudaLongTensor_nElement(state, indices); int srcDims = THCTensor_(nDimension)(state, src); cudaStream_t stream = THCState_getCurrentStream(state); THArgCheck(THCudaLongTensor_nDimension(state, indices) == 1, 3, "expecting vector of indices"); THArgCheck(dim < srcDims, 4, "Indexing dim is out of bounds"); THArgCheck(srcDims > 0, 2, "Source tensor is empty"); THArgCheck(numIndices == src->size[dim], 4, "length of src.size[dim] is not equal to length of indices"); int indContig = THCudaLongTensor_isContiguous(state, indices); </del> // The `src` is partitioned into two parts: // -the size of each slice we are indexing, which is the // total size of the tensor ignoring dimension `dim`; // -the number of indices we are choosing, which is the total size // of the tensor `indices`. <ins> ptrdiff_t sliceSize = THCTensor_(getSliceSize)(state, dst, dim, indices, src); </ins> ptrdiff_t srcTotalSize = THCTensor_(nElement)(state, src); int64_t dstCopyDimSize = THCTensor_(size)(state, dst, dim); <del> ptrdiff_t sliceSize = srcTotalSize / numIndices; </del> <ins> ptrdiff_t numIndices = THCudaLongTensor_nElement(state, indices); cudaStream_t stream = THCState_getCurrentStream(state); int indContig = THCudaLongTensor_isContiguous(state, indices); </ins> int mpc = THCState_getCurrentDeviceProperties(state)->multiProcessorCount;


The default value of `model_dir` is ``$TORCH_HOME/models`` where ``$TORCH_HOME`` defaults to ``~/.torch``. The default directory can be <del> overriden with the ``$TORCH_MODEL_ZOO`` environement variable. </del> <ins> overriden with the ``$TORCH_MODEL_ZOO`` environment variable. </ins> Args: url (string): URL of the object to download


# automatically filled by the dynamic loader. import os as _dl_flags <ins> # if we have numpy, it *must* be imported before the call to setdlopenflags() # or there is risk that later c modules will segfault when importing numpy try: import numpy as np except: pass </ins> # first check if the os package has the required flags if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_NOW'): try:


} __global__ void createBatchGemmBuffer3(const real** buffer1, const real ** buffer2, const real ** buffer3, real* data1, <del> real * data2, real * data3, long stride1, long stride2, long stride3, long num_batches) { const long idx = blockIdx.x * blockDim.x + threadIdx.x; </del> <ins> real * data2, real * data3, int64_t stride1, int64_t stride2, int64_t stride3, int64_t num_batches) { const int64_t idx = blockIdx.x * blockDim.x + threadIdx.x; </ins> if (idx < num_batches) { buffer1[idx] = data1 + idx * stride1; buffer2[idx] = data2 + idx * stride2;


), dict( module_name='Conv3d', <ins> constructor_args=(3, 4, (2, 3, 4), 1, 0, 1, 1, False), input_size=(2, 3, 3, 4, 5), cudnn=True, desc='no_bias' ), dict( module_name='Conv3d', </ins> constructor_args=(3, 4, 2, 2), input_size=(2, 3, 5, 5, 5), cudnn=True,


y_cpu_nhwc.data<float>(), y_cpu_nhwc.size()); int max_diff_idx = -1; (y_cpu_vec - y_gpu_vec).cwiseAbs().maxCoeff(&max_diff_idx); <del> EXPECT_FLOAT_EQ(y_cpu_vec[max_diff_idx], y_gpu_vec[max_diff_idx]); </del> <ins> EXPECT_NEAR(y_cpu_vec[max_diff_idx], y_gpu_vec[max_diff_idx], 1e-1); </ins> max_diff_idx = -1; (y_cpu_vec - y_cpu_nhwc_vec).cwiseAbs().maxCoeff(&max_diff_idx);


import sys import os <del> # TODO: make this more robust WITH_CUDA = os.path.exists('/Developer/NVIDIA/CUDA-7.5/include') or os.path.exists('/usr/local/cuda/include') </del> <ins> CUDA_HOME = os.getenv('CUDA_HOME', '/usr/local/cuda') WITH_CUDA = os.path.exists(CUDA_HOME) </ins> WITH_CUDNN = WITH_CUDA DEBUG = False


dims = THCudaLongTensor_nDimension(state, indices); THArgCheck(dims <= MAX_CUTORCH_DIMS, 4, CUTORCH_DIM_WARNING); <del> ptrdiff_t numIndices = THCudaLongTensor_nElement(state, indices); int srcDims = THCTensor_(nDimension)(state, src); cudaStream_t stream = THCState_getCurrentStream(state); THArgCheck(THCudaLongTensor_nDimension(state, indices) == 1, 3, "expecting vector of indices"); THArgCheck(dim < srcDims, 4, "Indexing dim is out of bounds"); THArgCheck(srcDims > 0, 2, "Source tensor is empty"); THArgCheck(numIndices == src->size[dim], 4, "length of src.size[dim] is not equal to length of indices"); int indContig = THCudaLongTensor_isContiguous(state, indices); </del> // The `src` is partitioned into two parts: // -the size of each slice we are indexing, which is the // total size of the tensor ignoring dimension `dim`; // -the number of indices we are choosing, which is the total size // of the tensor `indices`. <ins> ptrdiff_t sliceSize = THCTensor_(getSliceSize)(state, dst, dim, indices, src); </ins> ptrdiff_t srcTotalSize = THCTensor_(nElement)(state, src); int64_t dstAddDimSize = THCTensor_(size)(state, dst, dim); <del> ptrdiff_t sliceSize = srcTotalSize / numIndices; </del> <ins> ptrdiff_t numIndices = THCudaLongTensor_nElement(state, indices); cudaStream_t stream = THCState_getCurrentStream(state); int indContig = THCudaLongTensor_isContiguous(state, indices); </ins> int mpc = THCState_getCurrentDeviceProperties(state)->multiProcessorCount;


if (len(self.needs_input_grad) > 1 and self.needs_input_grad[2]) or self.use_cudnn: grad_bias = bias.new(bias.size()).zero_() <del> if self.use_cudnn: </del> <ins> if self.use_cudnn and self.training: # cudnn does not support backward in evaluate mode </ins> torch._C._cudnn_batch_norm_backward( input, grad_output, grad_input, grad_weight, grad_bias, weight,


array = np.array([1, 2, 3, 4], dtype=dtype) self.assertEqual(torch.from_numpy(array), torch.Tensor([1, 2, 3, 4])) <ins> # check storage offset x = np.linspace(1, 125, 125) x.shape = (5, 5, 5) x = x[1] expected = torch.range(1, 125).view(5, 5, 5)[1] self.assertEqual(torch.from_numpy(x), expected) # check noncontiguous x = np.linspace(1, 25, 25) x.shape = (5, 5) expected = torch.range(1, 25).view(5, 5).t() self.assertEqual(torch.from_numpy(x.T), expected) # check noncontiguous with holes x = np.linspace(1, 125, 125) x.shape = (5, 5, 5) x = x[:, 1] expected = torch.range(1, 125).view(5, 5, 5)[:, 1] self.assertEqual(torch.from_numpy(x), expected) </ins> @unittest.skipIf(not TEST_NUMPY, "Numpy not found") def test_numpy_index(self): i = np.int32([0, 1, 2])


def load_url(url, model_dir=None, map_location=None): r"""Loads the Torch serialized object at the given URL. <del> If the object is already present in `model_dir`, it's deserialied and </del> <ins> If the object is already present in `model_dir`, it's deserialized and </ins> returned. The filename part of the URL should follow the naming convention ``filename-<sha256>.ext`` where ``<sha256>`` is the first eight or more digits of the SHA256 hash of the contents of the file. The hash is used to


include("${CMAKE_UTILS_PATH}") torch_cuda_get_nvcc_gencode_flag(NVCC_GENCODE) <del> string (REPLACE ";" " " NVCC_GENCODE "${NVCC_GENCODE}") string (REPLACE "-gencode " "-gencode=" NVCC_GENCODE "${NVCC_GENCODE}") </del> <ins> string(REPLACE "-gencode;" "-gencode=" NVCC_GENCODE "${NVCC_GENCODE}") </ins> message(STATUS "Set NVCC_GENCODE for building NCCL: ${NVCC_GENCODE}") ADD_CUSTOM_COMMAND(


const auto& dim = tensor_names[idx]; TORCH_CHECK(dim.isBasic(), "align_to: All input dims must be named. Found unnamed dim at index ", <del> dim, " of Tensor", tensor_names); </del> <ins> idx, " of Tensor", tensor_names); </ins> auto it = std::find(names.begin(), names.end(), dim); TORCH_CHECK(it != names.end(), "align_to: Cannot find dim ", dim, " from Tensor", names,


#ifdef NUMPY_TYPE_ENUM THTensor* THPTensor_(fromNumpy)(PyObject *numpy_array) { PyArrayObject *array = (PyArrayObject*)numpy_array; <del> THStoragePtr storage = THStorage_(newWithDataAndAllocator)( (real*)PyArray_DATA(array), PyArray_NBYTES(array) / sizeof(real), &THNumpyArrayAllocator, new NumpyArrayAllocator(numpy_array)); </del> // Numpy and Torch disagree on empty tensors. In Torch, an empty // tensor is a tensor with zero dimensions. In Numpy, an empty tensor


return PyObject_CallFunctionObjArgs(THPLongTensorClass, array, NULL); } else if (type == NPY_INT32) { return PyObject_CallFunctionObjArgs(THPIntTensorClass, array, NULL); <ins> } else if (type == NPY_INT16) { return PyObject_CallFunctionObjArgs(THPShortTensorClass, array, NULL); </ins> } else if (type == NPY_UINT8) { return PyObject_CallFunctionObjArgs(THPByteTensorClass, array, NULL); }


THCTensor_(data)(state, result_), ldc, result_->stride[0], num_batches); } else { <del> for (long i = 0; i < num_batches; ++i) { </del> <ins> for (int64_t i = 0; i < num_batches; ++i) { </ins> THCudaBlas_Hgemm( state, transpose_batch1,


See :func:`torch.ormqr` """) <ins> add_docstr_all('permute', r""" permute(*dims) -> Tensor Permute the dimensions of this tensor. Args: *dims (int...): The desired ordering of dimensions Example: >>> x = torch.randn(2, 3, 5) >>> x.size() torch.Size([2, 3, 5]) >>> x.permute(2, 0, 1).size() torch.Size([5, 2, 3]) """) </ins> add_docstr_all('potrf', r""" potrf(upper=True) -> Tensor


pass if WITH_CUDA: <del> if platform.system() == 'Darwin': cuda_path = '/Developer/NVIDIA/CUDA-7.5' cuda_include_path = cuda_path + '/include' cuda_lib_path = cuda_path + '/lib' else: cuda_path = '/usr/local/cuda' cuda_include_path = cuda_path + '/include' cuda_lib_path = cuda_path + '/lib64' </del> <ins> cuda_lib_dirs = ['lib64', 'lib'] cuda_include_path = os.path.join(CUDA_HOME, 'include') for lib_dir in cuda_lib_dirs: cuda_lib_path = os.path.join(CUDA_HOME, lib_dir) if os.path.exists(cuda_lib_path): break </ins> include_dirs.append(cuda_include_path) extra_link_args.append('-L' + cuda_lib_path) extra_link_args.append('-Wl,-rpath,' + cuda_lib_path) extra_compile_args += ['-DWITH_CUDA'] <ins> extra_compile_args += ['-DCUDA_LIB_PATH=' + cuda_lib_path] </ins> main_libraries += ['THC'] main_sources += [ "torch/csrc/cuda/Module.cpp",


loss(x, y) = sum_ij(max(0, 1 - (x[y[j]] - x[i]))) / x.size(0) where `i == 0` to `x.size(0)`, `j == 0` to `y.size(0)`, <del> `y[j] != 0`, and `i != y[j]` for all `i` and `j`. </del> <ins> `y[j] >= 0`, and `i != y[j]` for all `i` and `j`. </ins> `y` and `x` must have the same size.


Alternatively, go to: https://pytorch.org/binaries to install a PyTorch version that has been compiled with your version of the CUDA driver.""".format(str(torch._C._cuda_getDriverVersion()))) <ins> def _lazy_init(): global _initialized, _cudart if _initialized: return _check_driver() </ins> assert torch._C._cuda_init() <del> _initialized = True if platform.system() == 'Darwin': _cudart = ctypes.cdll.LoadLibrary('libcudart.dylib') else: _cudart = ctypes.cdll.LoadLibrary('libcudart.so') </del> <ins> _cudart = _load_cudart() </ins> _cudart.cudaGetErrorName.restype = ctypes.c_char_p _cudart.cudaGetErrorString.restype = ctypes.c_char_p <ins> _initialized = True </ins> def cudart():


{"_cuda_sleep", (PyCFunction)THCPModule_cudaSleep, METH_O, NULL}, {"_cuda_lock_mutex",   (PyCFunction)THCPModule_cudaLockMutex,   METH_NOARGS,  NULL}, {"_cuda_unlock_mutex", (PyCFunction)THCPModule_cudaUnlockMutex, METH_NOARGS,  NULL}, <ins> #ifdef WITH_NCCL </ins> {"_nccl_reduce", (PyCFunction)THCPModule_nccl_reduce, METH_VARARGS, NULL}, {"_nccl_all_reduce", (PyCFunction)THCPModule_nccl_all_reduce, METH_VARARGS, NULL}, {"_nccl_broadcast", (PyCFunction)THCPModule_nccl_broadcast, METH_VARARGS, NULL}, {"_nccl_all_gather", (PyCFunction)THCPModule_nccl_all_gather, METH_VARARGS, NULL}, {"_nccl_reduce_scatter", (PyCFunction)THCPModule_nccl_reduce_scatter, METH_VARARGS, NULL}, <ins> #endif </ins> {NULL} };


"future releases."); return NULL; } <ins> // XXX: this won't work for negative strides storage_size += strides_data[i] * (sizes_data[i] - 1); </ins> } <ins> THStoragePtr storage = THStorage_(newWithDataAndAllocator)( (real*)PyArray_DATA(array), storage_size, &THNumpyArrayAllocator, new NumpyArrayAllocator(numpy_array)); </ins> THTensor *result = THTensor_(newWithStorage)(storage, 0, sizes, strides); return result; } else { <ins> THStoragePtr storage = THStorage_(new)(); </ins> THTensor *result = THTensor_(newWithStorage)(storage, 0, NULL, NULL); return result; }


int_classes = int <ins> if PY2: FileNotFoundError = IOError else: FileNotFoundError = FileNotFoundError </ins> def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" # This requires a bit of explanation: the basic idea is to make a dummy


dims = THCudaLongTensor_nDimension(state, indices); THArgCheck(dims <= MAX_CUTORCH_DIMS, 4, CUTORCH_DIM_WARNING); <del> ptrdiff_t numIndices = THCudaLongTensor_nElement(state, indices); int srcDims = THCTensor_(nDimension)(state, dst); cudaStream_t stream = THCState_getCurrentStream(state); THArgCheck(THCudaLongTensor_nDimension(state, indices) == 1, 3, "expecting vector of indices"); THArgCheck(dim < srcDims, 4, "Indexing dim is out of bounds"); THArgCheck(srcDims > 0, 2, "Source tensor is empty"); int indContig = THCudaLongTensor_isContiguous(state, indices); </del> // The `src` is partitioned into two parts: // -the size of each slice we are indexing, which is the // total size of the tensor ignoring dimension `dim`; // -the number of indices we are choosing, which is the total size // of the tensor `indices`. <ins> ptrdiff_t sliceSize = THCTensor_(getSliceSize)(state, dst, dim, indices, nullptr); </ins> ptrdiff_t dstTotalSize = THCTensor_(nElement)(state, dst); int64_t dstFillDimSize = THCTensor_(size)(state, dst, dim); <del> ptrdiff_t sliceSize = dstTotalSize / dstFillDimSize; </del> <ins> ptrdiff_t numIndices = THCudaLongTensor_nElement(state, indices); cudaStream_t stream = THCState_getCurrentStream(state); int indContig = THCudaLongTensor_isContiguous(state, indices); </ins> int mpc = THCState_getCurrentDeviceProperties(state)->multiProcessorCount;


for test in tests: _test(*test) <ins> @unittest.skip("Not implemented yet") </ins> def test_align_tensors(self): def reference_fn(*tensors): longest_names = tensors[0].names


class InstanceNorm1d(_InstanceNorm): <del> r"""Applies Instance Normalization over a 2d or 3d input that is seen as a mini-batch. </del> <ins> r"""Applies Instance Normalization over a 3d input that is seen as a mini-batch. </ins> .. math::


// TODO: gradOutput shape check // Resize and initialize result tensor. THCTensor_(resizeAs)(state, gradInput, input); <del> THCTensor_(newContiguous)(state, gradInput); </del> THCTensor_(zero)(state, gradInput); int batchSize;


Once these are installed, you can use the backend for Caffe2:: # ...continuing from above <del> import onnx.backend.caffe2 as backend </del> <ins> import onnx_caffe2.backend as backend </ins> import numpy as np rep = backend.prepare(graph, device="CUDA:0") # or "CPU" # For the Caffe2 backend: #     rep.predict_net is the Caffe2 protobuf for the network #     rep.workspace is the Caffe2 workspace for the network <del> #       (see the class onnx.backend.c2.Workspace) </del> <ins> #       (see the class onnx_caffe2.backend.Workspace) </ins> outputs = rep.run(np.random.randn(10, 3, 224, 224).astype(np.float32)) # To run networks with more than one input, pass a tuple # rather than a single numpy ndarray.


import contextlib import platform import ctypes <ins> import os </ins> import torch _initialized = False


Threshold is defined as:: <del> y =  x        if x >= threshold value    if x <  threshold </del> <ins> y =  x        if x >  threshold value    if x <= threshold </ins> Args: threshold: The value to threshold at


#ifdef TH_REAL_IS_INT #define NUMPY_TYPE_ENUM NPY_INT32 #endif <ins> #ifdef TH_REAL_IS_SHORT #define NUMPY_TYPE_ENUM NPY_INT16 #endif </ins> #ifdef TH_REAL_IS_BYTE #define NUMPY_TYPE_ENUM NPY_UINT8 #endif


{"_cuda_initialSeed", (PyCFunction)THCPModule_initialSeed, METH_NOARGS, NULL}, {"_cuda_cudaHostAllocator", (PyCFunction)THCPModule_cudaHostAllocator, METH_NOARGS, NULL}, {"_cuda_synchronize", (PyCFunction)THCPModule_cudaSynchronize, METH_NOARGS, NULL}, <ins> {"_cuda_getLibPath", (PyCFunction)THCPModule_getLibPath, METH_NOARGS, NULL}, </ins> #endif {"_safe_call",      (PyCFunction)THPModule_safeCall,          METH_VARARGS | METH_KEYWORDS, NULL}, {"_sendfd",         (PyCFunction)THPModule_sendfd,            METH_VARARGS, NULL},


def align_tensors(*tensors): <del> if not torch._C._BUILD_NAMEDTENSOR: raise RuntimeError('NYI: torch.align_tensors is experimental and a part ' 'of our named tensors project.') return torch._C._VariableFunctions.align_tensors(tensors) </del> <ins> raise RuntimeError('`align_tensors` not yet implemented.') </ins>


return (hasattr(torch._C, '_cuda_isDriverSufficient') and torch._C._cuda_isDriverSufficient()) <del> def _lazy_init(): global _initialized, _cudart if _initialized: return </del> <ins> def _load_cudart(): system = platform.system() lib_name = 'libcudart.' + ('dylib' if system == 'Darwin' else 'so') lib_paths = [ lib_name, os.path.join(torch._C._cuda_getLibPath(), lib_name), os.path.join('/usr/local/cuda/lib64', lib_name), os.path.join('/usr/local/cuda/lib', lib_name), ] for path in lib_paths: try: return ctypes.cdll.LoadLibrary(path) except OSError: pass raise RuntimeError("couldn't find libcudart. Make sure CUDA libraries " "are installed in a default location, or that they're in " + ("DYLD_LIBRARY_PATH" if system == 'Darwin' else "LD_LIBRARY_PATH") + ".") def _check_driver(): </ins> if not hasattr(torch._C, '_cuda_isDriverSufficient'): raise AssertionError("Torch not compiled with CUDA enabled") if not torch._C._cuda_isDriverSufficient():


extern PyObject * THCPModule_initialSeed(PyObject *_unused); extern PyObject * THCPModule_cudaHostAllocator(PyObject *_unused); extern PyObject * THCPModule_cudaSynchronize(PyObject *_unused); <ins> extern PyObject * THCPModule_getLibPath(PyObject *_unused); </ins> #endif static PyMethodDef TorchMethods[] = {


.. math:: f(X) = sqrt[p]{sum_{x in X} x^{p}} <del> - At p = infinity, one gets Max Pooling - At p = 1, one gets Average Pooling </del> <ins> - At p = infinity, one gets Max Pooling - At p = 1, one gets Sum Pooling (which is proportional to Average Pooling) </ins> Args: kernel_size: a single int, the size of the window


np.float, np.int64, np.int32, <ins> np.int16, </ins> np.uint8 ] for dtype in dtypes: