CodeConvo / pytorch /c2i /test /queries.jsonl
jiebi's picture
Upload CodeConvo dataset
c2b8f63 verified
{"_id":"q-en-pytorch-01e2b4fe338d07f5af44fa823ad671eec321befe4c853924dccaebac1bc2bb07","text":"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):"}
{"_id":"q-en-pytorch-09cd3f53efdef2b3c62dfceda20d3726a41e47d2c2f1c7403694b2895c64618d","text":"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"}
{"_id":"q-en-pytorch-0c1d2b21c3aed080ff0bb21e80fe229ef6f87b04f7463a20a1f6ac34395f0a04","text":"#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));"}
{"_id":"q-en-pytorch-0ea112482f01ac9ba7726d29bb245cd1439c8652994ad3114f6aa3829f2956d6","text":".. 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:"}
{"_id":"q-en-pytorch-1b4e7aa1671c70fbb6651879b00382e5f9201723445de8bbcde6263cb671c32e","text":"} #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) )"}
{"_id":"q-en-pytorch-2061ca1f7c9ba9b98280c54731796670bfcef58e0bee1f86177c3af1aa68c348","text":"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 ////////////////////////////////////////////////////////////////////////////////"}
{"_id":"q-en-pytorch-21b3696252b2695784a3bde6bacc43b8018c770240f0452e79fe18b404ffe3cb","text":"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):"}
{"_id":"q-en-pytorch-23fe48427cf620ea487ef20f4cf01cf6e9e28870f31d422e54ff4859b03f770f","text":"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 <>"}
{"_id":"q-en-pytorch-26f0793d6ce40355c03e73f96fb27c17c1f989bb6b77877c3db6dd237f8e947b","text":"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:"}
{"_id":"q-en-pytorch-32776d38967a25e19b1cd4258a1be0599dcf2c5549e9e14e8a2c1bf2b1c20c8e","text":"#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 */"}
{"_id":"q-en-pytorch-3d10053dde46b7e17c674ada139bb7892f1a4a007d21e792e44f8b8cd4f78cdb","text":"// 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) {"}
{"_id":"q-en-pytorch-406d300c4698ef8ebb5337a06de7733923ff9b8c1d75f141fdd19816f61b98ae","text":"import os.path import torch.nn.modules.activation import torch.autograd <ins> import matplotlib matplotlib.use('Agg') </ins> import pylab"}
{"_id":"q-en-pytorch-409db2af998ca52110af23f85fedd2c1b518b999578c78c48c50c68aac9dfc64","text":"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"}
{"_id":"q-en-pytorch-438f0cd197dc41837843b0b79dcabb3cb7066f26b861da7f1fd39c8db8f72698","text":"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;"}
{"_id":"q-en-pytorch-43d57642c8f2c4fd5288a498e2570bc0f7f415e4f84ca50f6db7ed554a36f458","text":"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"}
{"_id":"q-en-pytorch-4c3a71901fc795799e7b19b3c7a183ac183e7e015fb5cc2de8be660334bd3f51","text":"# 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:"}
{"_id":"q-en-pytorch-4c4cbb1f5bc5fc20180477ba87f3b48250f4ba3e123fb7768b93aaaa18a0799b","text":"} __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;"}
{"_id":"q-en-pytorch-4d40076fff0cbd05c0f0272876a90feb73d0e9119f736bed7d31cedc975e7e1a","text":"), 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,"}
{"_id":"q-en-pytorch-57fd75dd746340c02c696b27c9ace5c457ab117c6fa87fcc3505b1f1b746ea12","text":"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);"}
{"_id":"q-en-pytorch-5bf879202fe41f577d1528504bb7124967a8aa4306ba6d028133e54ed2a46c6a","text":"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"}
{"_id":"q-en-pytorch-606249d4e5065e174d0bb8445e4f0794e1c65b557690f03981584032238bd0cb","text":"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;"}
{"_id":"q-en-pytorch-60e6da6614bf79d4c81c4d31a075bb53bfcf1fe5ed6126a0936df3b5f19ccf48","text":"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,"}
{"_id":"q-en-pytorch-64952c8e117e17a5ca2533969d98778d5fe1704750b2d75e840978c01a057f7d","text":"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])"}
{"_id":"q-en-pytorch-650c90e1a3d73165b3a5db0a44dea751d15caee691c2d34fcabdb385ae7cfd9a","text":"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"}
{"_id":"q-en-pytorch-6749361c7ea8d94cb25e13ac96078140852bf945bb508690649257e713b72470","text":"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("}
{"_id":"q-en-pytorch-6cd27db7bbea6d45658fa436474e19a3230f031f8b61ffd45dc8cbadd253e1f7","text":"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,"}
{"_id":"q-en-pytorch-739905d98d898468387484bc0e4f63dd7bb3cff90818792350c0ab82bd4674e3","text":"#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"}
{"_id":"q-en-pytorch-7ecc74cf7a8b83f2918637652e8727b1637f12f8d4b8759c379088ceea9916a0","text":"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); }"}
{"_id":"q-en-pytorch-8346a42adf2a20bb7a3cbc59d07bfd3339fc72f8d80019c104e4b3d546917bce","text":"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,"}
{"_id":"q-en-pytorch-85de7ca993fe71820aa6914403ef4020c7c221a26a264b8143092c58d899fe53","text":"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"}
{"_id":"q-en-pytorch-89e3e6bdb26578265a955db96af03126e423ed91e9beb46c903f76b826d5780e","text":"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\","}
{"_id":"q-en-pytorch-8b58474d691d2e15d1e08141e0e6d0dce367ca48a9be5d0bf5339f905b57573b","text":"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."}
{"_id":"q-en-pytorch-8bb134eb0920ef385d213f78151b35474e5a8c3112336b15dfae21edffb82304","text":"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():"}
{"_id":"q-en-pytorch-919c10dadeb43db59d5c9303c047eb60d6809352738af2e454a2c9f6f8045af7","text":"{\"_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} };"}
{"_id":"q-en-pytorch-970f45d0dc765152918981884254d63eb61894a68eba97a7c30729442e9675af","text":"\"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; }"}
{"_id":"q-en-pytorch-9984ee82d4490f95cf1b5549fdfa93cabf578a9aed1621ea7695d65eb663fdf4","text":"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"}
{"_id":"q-en-pytorch-a7f5f31517bc2f93e661073a8055244cb988c558177acffc671e7b7f0c3b5dfc","text":"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;"}
{"_id":"q-en-pytorch-a81e6151b9e45c151c86e332d830aa52c8dfc7010c288dabeaa2a6b4b048a4a9","text":"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"}
{"_id":"q-en-pytorch-ab5d15d7dd094ae2fa817a899a919076d0ea03d9cb234cc7881a60bf6904f2a2","text":"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::"}
{"_id":"q-en-pytorch-b85baf3b49273dd2135f72d0e09e246f96aaa047538243ca634f0a03a702b9f3","text":"// 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;"}
{"_id":"q-en-pytorch-bb1cd692f90c2a52292d5a2b7aad0a809e6487387b0460bdb0ecbcb9aee58805","text":"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."}
{"_id":"q-en-pytorch-bb9dc467b4098d579f411e64f059a5d51c87ab0ca69a149799adb059f3dc2657","text":"import contextlib import platform import ctypes <ins> import os </ins> import torch _initialized = False"}
{"_id":"q-en-pytorch-c4618373d440907e1f401a56ccadf8cd14fccfb4e8cb88c2edde7bdce55d57ab","text":"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"}
{"_id":"q-en-pytorch-ce02830fb76522fb46cdd15ed92cd7f26880cbfff6e16ee2322eac970cdb7ebe","text":"#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"}
{"_id":"q-en-pytorch-db0578e90ce1ed1beb7b7ec598d26185a9e2abbab8bf9d89784a28742d6b16a4","text":"{\"_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},"}
{"_id":"q-en-pytorch-dc5476dca0cbdb1ef52d90efeb4a0f4004888ebed034e1ef2c1222b4241d29be","text":"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>"}
{"_id":"q-en-pytorch-de06230c6d43c431a6f7a275642da501bed88c2969a51d8612d8f99249fb61e3","text":"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():"}
{"_id":"q-en-pytorch-df3cd13f32f960ed5135f9b9d851fc5082eea1f2fb2d456402fb2815c37dc5ce","text":"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[] = {"}
{"_id":"q-en-pytorch-eead1b452de8c5cf90bef351b8c615d64f8e787012ed322d9368522c8fd013f1","text":".. 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"}
{"_id":"q-en-pytorch-f44b85ebdbf00d0ba828274a4f940924c2065b2b870adae6faab246645d80f6e","text":"np.float, np.int64, np.int32, <ins> np.int16, </ins> np.uint8 ] for dtype in dtypes:"}