neulab/docprompting-conala huggingface dataset:
torch.random  
torch.random.fork_rng(devices=None, enabled=True, _caller='fork_rng', _devices_kw='devices') [source]
 
Forks the RNG, so that when you return, the RNG is reset to the state that it was previously in.  Parameters 
 
devices (iterable of CUDA IDs) – CUDA devices for which to fork the RNG. CPU RNG state is always forked. By default, fork_rng() operates on all devices, but will emit a warning if your machine has a lot of devices, since this function will run very slowly in that case. If you explicitly specify devices, this warning will be suppressed 
enabled (bool) – if False, the RNG is not forked. This is a convenience argument for easily disabling the context manager without having to delete it and unindent your Python code under it.    
  
torch.random.get_rng_state() [source]
 
Returns the random number generator state as a torch.ByteTensor. 
  
torch.random.initial_seed() [source]
 
Returns the initial seed for generating random numbers as a Python long. 
  
torch.random.manual_seed(seed) [source]
 
Sets the seed for generating random numbers. Returns a torch.Generator object.  Parameters 
seed (int) – The desired seed. Value must be within the inclusive range [-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]. Otherwise, a RuntimeError is raised. Negative inputs are remapped to positive values with the formula 0xffff_ffff_ffff_ffff + seed.   
  
torch.random.seed() [source]
 
Sets the seed for generating random numbers to a non-deterministic random number. Returns a 64 bit number used to seed the RNG. 
  
torch.random.set_rng_state(new_state) [source]
 
Sets the random number generator state.  Parameters 
new_state (torch.ByteTensor) – The desired state
torch.random.fork_rng(devices=None, enabled=True, _caller='fork_rng', _devices_kw='devices') [source]
 
Forks the RNG, so that when you return, the RNG is reset to the state that it was previously in.  Parameters 
 
devices (iterable of CUDA IDs) – CUDA devices for which to fork the RNG. CPU RNG state is always forked. By default, fork_rng() operates on all devices, but will emit a warning if your machine has a lot of devices, since this function will run very slowly in that case. If you explicitly specify devices, this warning will be suppressed 
enabled (bool) – if False, the RNG is not forked. This is a convenience argument for easily disabling the context manager without having to delete it and unindent your Python code under it.
torch.random.get_rng_state() [source]
 
Returns the random number generator state as a torch.ByteTensor.
torch.random.initial_seed() [source]
 
Returns the initial seed for generating random numbers as a Python long.
torch.random.manual_seed(seed) [source]
 
Sets the seed for generating random numbers. Returns a torch.Generator object.  Parameters 
seed (int) – The desired seed. Value must be within the inclusive range [-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]. Otherwise, a RuntimeError is raised. Negative inputs are remapped to positive values with the formula 0xffff_ffff_ffff_ffff + seed.
torch.random.seed() [source]
 
Sets the seed for generating random numbers to a non-deterministic random number. Returns a 64 bit number used to seed the RNG.
torch.random.set_rng_state(new_state) [source]
 
Sets the random number generator state.  Parameters 
new_state (torch.ByteTensor) – The desired state
torch.randperm(n, *, generator=None, out=None, dtype=torch.int64, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) → Tensor  
Returns a random permutation of integers from 0 to n - 1.  Parameters 
n (int) – the upper bound (exclusive)  Keyword Arguments 
 
generator (torch.Generator, optional) – a pseudorandom number generator for sampling 
out (Tensor, optional) – the output tensor. 
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: torch.int64. 
layout (torch.layout, optional) – the desired layout of returned Tensor. Default: torch.strided. 
device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. 
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False. 
pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.    Example: >>> torch.randperm(4)
tensor([2, 1, 0, 3])
torch.rand_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) → Tensor  
Returns a tensor with the same size as input that is filled with random numbers from a uniform distribution on the interval [0,1)[0, 1) . torch.rand_like(input) is equivalent to torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).  Parameters 
input (Tensor) – the size of input will determine size of the output tensor.  Keyword Arguments 
 
dtype (torch.dtype, optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. 
layout (torch.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. 
device (torch.device, optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. 
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False. 
memory_format (torch.memory_format, optional) – the desired memory format of returned Tensor. Default: torch.preserve_format.
torch.range(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor  
Returns a 1-D tensor of size ⌊end−startstep⌋+1\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1  with values from start to end with step step. Step is the gap between two values in the tensor.  outi+1=outi+step.\text{out}_{i+1} = \text{out}_i + \text{step}.  
 Warning This function is deprecated and will be removed in a future release because its behavior is inconsistent with Python’s range builtin. Instead, use torch.arange(), which produces values in [start, end).   Parameters 
 
start (float) – the starting value for the set of points. Default: 0. 
end (float) – the ending value for the set of points 
step (float) – the gap between each pair of adjacent points. Default: 1.   Keyword Arguments 
 
out (Tensor, optional) – the output tensor. 
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()). If dtype is not given, infer the data type from the other input arguments. If any of start, end, or stop are floating-point, the dtype is inferred to be the default dtype, see get_default_dtype(). Otherwise, the dtype is inferred to be torch.int64. 
layout (torch.layout, optional) – the desired layout of returned Tensor. Default: torch.strided. 
device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. 
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.    Example: >>> torch.range(1, 4)
tensor([ 1.,  2.,  3.,  4.])
>>> torch.range(1, 4, 0.5)
tensor([ 1.0000,  1.5000,  2.0000,  2.5000,  3.0000,  3.5000,  4.0000])
torch.ravel(input) → Tensor  
Return a contiguous flattened tensor. A copy is made only if needed.  Parameters 
input (Tensor) – the input tensor.   Example: >>> t = torch.tensor([[[1, 2],
...                    [3, 4]],
...                   [[5, 6],
...                    [7, 8]]])
>>> torch.ravel(t)
tensor([1, 2, 3, 4, 5, 6, 7, 8])
torch.real(input) → Tensor  
Returns a new tensor containing real values of the self tensor. The returned tensor and self share the same underlying storage.  Warning real() is only supported for tensors with complex dtypes.   Parameters 
input (Tensor) – the input tensor.    Example::

>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
>>> x.real
tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
torch.reciprocal(input, *, out=None) → Tensor  
Returns a new tensor with the reciprocal of the elements of input  Note Unlike NumPy’s reciprocal, torch.reciprocal supports integral inputs. Integral inputs to reciprocal are automatically promoted to the default scalar type.   outi=1inputi\text{out}_{i} = \frac{1}{\text{input}_{i}}  
 Parameters 
input (Tensor) – the input tensor.  Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([-0.4595, -2.1219, -1.4314,  0.7298])
>>> torch.reciprocal(a)
tensor([-2.1763, -0.4713, -0.6986,  1.3702])
torch.remainder(input, other, *, out=None) → Tensor  
Computes the element-wise remainder of division. The dividend and divisor may contain both for integer and floating point numbers. The remainder has the same sign as the divisor other. Supports broadcasting to a common shape, type promotion, and integer and float inputs.  Note Complex inputs are not supported. In some cases, it is not mathematically possible to satisfy the definition of a modulo operation with complex numbers. See torch.fmod() for how division by zero is handled.   Parameters 
 
input (Tensor) – the dividend 
other (Tensor or Scalar) – the divisor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
tensor([ 1.,  0.,  1.,  1.,  0.,  1.])
>>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), 1.5)
tensor([ 1.0000,  0.5000,  0.0000,  1.0000,  0.5000])
  See also torch.fmod(), which computes the element-wise remainder of division equivalently to the C library function fmod().
torch.renorm(input, p, dim, maxnorm, *, out=None) → Tensor  
Returns a tensor where each sub-tensor of input along dimension dim is normalized such that the p-norm of the sub-tensor is lower than the value maxnorm  Note If the norm of a row is lower than maxnorm, the row is unchanged   Parameters 
 
input (Tensor) – the input tensor. 
p (float) – the power for the norm computation 
dim (int) – the dimension to slice over to get the sub-tensors 
maxnorm (float) – the maximum norm to keep each sub-tensor under   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> x = torch.ones(3, 3)
>>> x[1].fill_(2)
tensor([ 2.,  2.,  2.])
>>> x[2].fill_(3)
tensor([ 3.,  3.,  3.])
>>> x
tensor([[ 1.,  1.,  1.],
        [ 2.,  2.,  2.],
        [ 3.,  3.,  3.]])
>>> torch.renorm(x, 1, 0, 5)
tensor([[ 1.0000,  1.0000,  1.0000],
        [ 1.6667,  1.6667,  1.6667],
        [ 1.6667,  1.6667,  1.6667]])
torch.repeat_interleave(input, repeats, dim=None) → Tensor  
Repeat elements of a tensor.  Warning This is different from torch.Tensor.repeat() but similar to numpy.repeat.   Parameters 
 
input (Tensor) – the input tensor. 
repeats (Tensor or int) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis. 
dim (int, optional) – The dimension along which to repeat values. By default, use the flattened input array, and return a flat output array.   Returns 
Repeated tensor which has the same shape as input, except along the given axis.  Return type 
Tensor   Example: >>> x = torch.tensor([1, 2, 3])
>>> x.repeat_interleave(2)
tensor([1, 1, 2, 2, 3, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.repeat_interleave(y, 2)
tensor([1, 1, 2, 2, 3, 3, 4, 4])
>>> torch.repeat_interleave(y, 3, dim=1)
tensor([[1, 1, 1, 2, 2, 2],
        [3, 3, 3, 4, 4, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
tensor([[1, 2],
        [3, 4],
        [3, 4]])
  
torch.repeat_interleave(repeats) → Tensor 
 If the repeats is tensor([n1, n2, n3, …]), then the output will be tensor([0, 0, …, 1, 1, …, 2, 2, …, …]) where 0 appears n1 times, 1 appears n2 times, 2 appears n3 times, etc.
torch.reshape(input, shape) → Tensor  
Returns a tensor with the same data and number of elements as input, but with the specified shape. When possible, the returned tensor will be a view of input. Otherwise, it will be a copy. Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior. See torch.Tensor.view() on when it is possible to return a view. A single dimension may be -1, in which case it’s inferred from the remaining dimensions and the number of elements in input.  Parameters 
 
input (Tensor) – the tensor to be reshaped 
shape (tuple of python:ints) – the new shape    Example: >>> a = torch.arange(4.)
>>> torch.reshape(a, (2, 2))
tensor([[ 0.,  1.],
        [ 2.,  3.]])
>>> b = torch.tensor([[0, 1], [2, 3]])
>>> torch.reshape(b, (-1,))
tensor([ 0,  1,  2,  3])
torch.result_type(tensor1, tensor2) → dtype  
Returns the torch.dtype that would result from performing an arithmetic operation on the provided input tensors. See type promotion documentation for more information on the type promotion logic.  Parameters 
 
tensor1 (Tensor or Number) – an input tensor or number 
tensor2 (Tensor or Number) – an input tensor or number    Example: >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
torch.float32
>>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
torch.uint8
torch.roll(input, shifts, dims=None) → Tensor  
Roll the tensor along the given dimension(s). Elements that are shifted beyond the last position are re-introduced at the first position. If a dimension is not specified, the tensor will be flattened before rolling and then restored to the original shape.  Parameters 
 
input (Tensor) – the input tensor. 
shifts (int or tuple of python:ints) – The number of places by which the elements of the tensor are shifted. If shifts is a tuple, dims must be a tuple of the same size, and each dimension will be rolled by the corresponding value 
dims (int or tuple of python:ints) – Axis along which to roll    Example: >>> x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2)
>>> x
tensor([[1, 2],
        [3, 4],
        [5, 6],
        [7, 8]])
>>> torch.roll(x, 1, 0)
tensor([[7, 8],
        [1, 2],
        [3, 4],
        [5, 6]])
>>> torch.roll(x, -1, 0)
tensor([[3, 4],
        [5, 6],
        [7, 8],
        [1, 2]])
>>> torch.roll(x, shifts=(2, 1), dims=(0, 1))
tensor([[6, 5],
        [8, 7],
        [2, 1],
        [4, 3]])
torch.rot90(input, k, dims) → Tensor  
Rotate a n-D tensor by 90 degrees in the plane specified by dims axis. Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.  Parameters 
 
input (Tensor) – the input tensor. 
k (int) – number of times to rotate 
dims (a list or tuple) – axis to rotate    Example: >>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
        [2, 3]])
>>> torch.rot90(x, 1, [0, 1])
tensor([[1, 3],
        [0, 2]])

>>> x = torch.arange(8).view(2, 2, 2)
>>> x
tensor([[[0, 1],
         [2, 3]],

        [[4, 5],
         [6, 7]]])
>>> torch.rot90(x, 1, [1, 2])
tensor([[[1, 3],
         [0, 2]],

        [[5, 7],
         [4, 6]]])
torch.round(input, *, out=None) → Tensor  
Returns a new tensor with each of the elements of input rounded to the closest integer.  Parameters 
input (Tensor) – the input tensor.  Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([ 0.9920,  0.6077,  0.9734, -1.0362])
>>> torch.round(a)
tensor([ 1.,  1.,  1., -1.])
torch.row_stack(tensors, *, out=None) → Tensor  
Alias of torch.vstack().
torch.rsqrt(input, *, out=None) → Tensor  
Returns a new tensor with the reciprocal of the square-root of each of the elements of input.  outi=1inputi\text{out}_{i} = \frac{1}{\sqrt{\text{input}_{i}}}  
 Parameters 
input (Tensor) – the input tensor.  Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([-0.0370,  0.2970,  1.5420, -0.9105])
>>> torch.rsqrt(a)
tensor([    nan,  1.8351,  0.8053,     nan])
torch.save(obj, f, pickle_module=<module 'pickle' from '/home/matti/miniconda3/lib/python3.7/pickle.py'>, pickle_protocol=2, _use_new_zipfile_serialization=True) [source]
 
Saves an object to a disk file. See also: saving-loading-tensors  Parameters 
 
obj – saved object 
f – a file-like object (has to implement write and flush) or a string or os.PathLike object containing a file name 
pickle_module – module used for pickling metadata and objects 
pickle_protocol – can be specified to override the default protocol     Note A common PyTorch convention is to save tensors using .pt file extension.   Note PyTorch preserves storage sharing across serialization. See preserve-storage-sharing for more details.   Note The 1.6 release of PyTorch switched torch.save to use a new zipfile-based file format. torch.load still retains the ability to load files in the old format. If for any reason you want torch.save to use the old format, pass the kwarg _use_new_zipfile_serialization=False.  Example >>> # Save to file
>>> x = torch.tensor([0, 1, 2, 3, 4])
>>> torch.save(x, 'tensor.pt')
>>> # Save to io.BytesIO buffer
>>> buffer = io.BytesIO()
>>> torch.save(x, buffer)
torch.scatter(input, dim, index, src) → Tensor  
Out-of-place version of torch.Tensor.scatter_()
torch.scatter_add(input, dim, index, src) → Tensor  
Out-of-place version of torch.Tensor.scatter_add_()
torch.searchsorted(sorted_sequence, values, *, out_int32=False, right=False, out=None) → Tensor  
Find the indices from the innermost dimension of sorted_sequence such that, if the corresponding values in values were inserted before the indices, the order of the corresponding innermost dimension within sorted_sequence would be preserved. Return a new tensor with the same size as values. If right is False (default), then the left boundary of sorted_sequence is closed. More formally, the returned index satisfies the following rules:   
sorted_sequence right returned index satisfies   
1-D False sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]  
1-D True sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]  
N-D False sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]  
N-D True sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]    Parameters 
 
sorted_sequence (Tensor) – N-D or 1-D tensor, containing monotonically increasing sequence on the innermost dimension. 
values (Tensor or Scalar) – N-D tensor or a Scalar containing the search value(s).   Keyword Arguments 
 
out_int32 (bool, optional) – indicate the output data type. torch.int32 if True, torch.int64 otherwise. Default value is False, i.e. default output data type is torch.int64. 
right (bool, optional) – if False, return the first suitable location that is found. If True, return the last such index. If no suitable index found, return 0 for non-numerical value (eg. nan, inf) or the size of innermost dimension within sorted_sequence (one pass the last index of the innermost dimension). In other words, if False, gets the lower bound index for each value in values on the corresponding innermost dimension of the sorted_sequence. If True, gets the upper bound index instead. Default value is False. 
out (Tensor, optional) – the output tensor, must be the same size as values if provided.     Note If your use case is always 1-D sorted sequence, torch.bucketize() is preferred, because it has fewer dimension checks resulting in slightly better performance.  Example: >>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
>>> sorted_sequence
tensor([[ 1,  3,  5,  7,  9],
        [ 2,  4,  6,  8, 10]])
>>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
>>> values
tensor([[3, 6, 9],
        [3, 6, 9]])
>>> torch.searchsorted(sorted_sequence, values)
tensor([[1, 3, 4],
        [1, 2, 4]])
>>> torch.searchsorted(sorted_sequence, values, right=True)
tensor([[2, 3, 5],
        [1, 3, 4]])

>>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
>>> sorted_sequence_1d
tensor([1, 3, 5, 7, 9])
>>> torch.searchsorted(sorted_sequence_1d, values)
tensor([[1, 3, 4],
        [1, 3, 4]])
torch.seed() [source]
 
Sets the seed for generating random numbers to a non-deterministic random number. Returns a 64 bit number used to seed the RNG.
torch.set_default_dtype(d) [source]
 
Sets the default floating point dtype to d. This dtype is:  The inferred dtype for python floats in torch.tensor(). Used to infer dtype for python complex numbers. The default complex dtype is set to torch.complex128 if default floating point dtype is torch.float64, otherwise it’s set to torch.complex64
  The default floating point dtype is initially torch.float32.  Parameters 
d (torch.dtype) – the floating point dtype to make the default   Example >>> # initial default for floating point is torch.float32
>>> torch.tensor([1.2, 3]).dtype
torch.float32
>>> # initial default for floating point is torch.complex64
>>> torch.tensor([1.2, 3j]).dtype
torch.complex64
>>> torch.set_default_dtype(torch.float64)
>>> torch.tensor([1.2, 3]).dtype    # a new floating point tensor
torch.float64
>>> torch.tensor([1.2, 3j]).dtype   # a new complex tensor
torch.complex128
torch.set_default_tensor_type(t) [source]
 
Sets the default torch.Tensor type to floating point tensor type t. This type will also be used as default floating point type for type inference in torch.tensor(). The default floating point tensor type is initially torch.FloatTensor.  Parameters 
t (type or string) – the floating point tensor type or its name   Example: >>> torch.tensor([1.2, 3]).dtype    # initial default for floating point is torch.float32
torch.float32
>>> torch.set_default_tensor_type(torch.DoubleTensor)
>>> torch.tensor([1.2, 3]).dtype    # a new floating point tensor
torch.float64
torch.set_flush_denormal(mode) → bool  
Disables denormal floating numbers on CPU. Returns True if your system supports flushing denormal numbers and it successfully configures flush denormal mode. set_flush_denormal() is only supported on x86 architectures supporting SSE3.  Parameters 
mode (bool) – Controls whether to enable flush denormal mode or not   Example: >>> torch.set_flush_denormal(True)
True
>>> torch.tensor([1e-323], dtype=torch.float64)
tensor([ 0.], dtype=torch.float64)
>>> torch.set_flush_denormal(False)
True
>>> torch.tensor([1e-323], dtype=torch.float64)
tensor(9.88131e-324 *
       [ 1.0000], dtype=torch.float64)
class torch.set_grad_enabled(mode) [source]
 
Context-manager that sets gradient calculation to on or off. set_grad_enabled will enable or disable grads based on its argument mode. It can be used as a context-manager or as a function. This context manager is thread local; it will not affect computation in other threads.  Parameters 
mode (bool) – Flag whether to enable grad (True), or disable (False). This can be used to conditionally enable gradients.   Example: >>> x = torch.tensor([1], requires_grad=True)
>>> is_train = False
>>> with torch.set_grad_enabled(is_train):
...   y = x * 2
>>> y.requires_grad
False
>>> torch.set_grad_enabled(True)
>>> y = x * 2
>>> y.requires_grad
True
>>> torch.set_grad_enabled(False)
>>> y = x * 2
>>> y.requires_grad
False
torch.set_num_interop_threads(int)  
Sets the number of threads used for interop parallelism (e.g. in JIT interpreter) on CPU.  Warning Can only be called once and before any inter-op parallel work is started (e.g. JIT execution).
torch.set_num_threads(int)  
Sets the number of threads used for intraop parallelism on CPU.  Warning To ensure that the correct number of threads is used, set_num_threads must be called before running eager, JIT or autograd code.