neulab/docprompting-conala huggingface dataset:
torch.hub.load(repo_or_dir, model, *args, **kwargs) [source]
 
Load a model from a github repo or a local directory. Note: Loading a model is the typical use case, but this can also be used to for loading other objects such as tokenizers, loss functions, etc. If source is 'github', repo_or_dir is expected to be of the form repo_owner/repo_name[:tag_name] with an optional tag/branch. If source is 'local', repo_or_dir is expected to be a path to a local directory.  Parameters 
 
repo_or_dir (string) – repo name (repo_owner/repo_name[:tag_name]), if source = 'github'; or a path to a local directory, if source = 'local'. 
model (string) – the name of a callable (entrypoint) defined in the repo/dir’s hubconf.py. 
*args (optional) – the corresponding args for callable model. 
source (string, optional) – 'github' | 'local'. Specifies how repo_or_dir is to be interpreted. Default is 'github'. 
force_reload (bool, optional) – whether to force a fresh download of the github repo unconditionally. Does not have any effect if source = 'local'. Default is False. 
verbose (bool, optional) – If False, mute messages about hitting local caches. Note that the message about first download cannot be muted. Does not have any effect if source = 'local'. Default is True. 
**kwargs (optional) – the corresponding kwargs for callable model.   Returns 
The output of the model callable when called with the given *args and **kwargs.   Example >>> # from a github repo
>>> repo = 'pytorch/vision'
>>> model = torch.hub.load(repo, 'resnet50', pretrained=True)
>>> # from a local directory
>>> path = '/some/local/path/pytorch/vision'
>>> model = torch.hub.load(path, 'resnet50', pretrained=True)
torch.hub.load_state_dict_from_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None) [source]
 
Loads the Torch serialized object at the given URL. If downloaded file is a zip file, it will be automatically decompressed. If the object is already present in model_dir, it’s deserialized and returned. The default value of model_dir is <hub_dir>/checkpoints where hub_dir is the directory returned by get_dir().  Parameters 
 
url (string) – URL of the object to download 
model_dir (string, optional) – directory in which to save the object 
map_location (optional) – a function or a dict specifying how to remap storage locations (see torch.load) 
progress (bool, optional) – whether or not to display a progress bar to stderr. Default: True 
check_hash (bool, optional) – If True, 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 ensure unique names and to verify the contents of the file. Default: False 
file_name (string, optional) – name for the downloaded file. Filename from url will be used if not set.    Example >>> state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')
torch.hub.set_dir(d) [source]
 
Optionally set the Torch Hub directory used to save downloaded models & weights.  Parameters 
d (string) – path to a local folder to save downloaded models & weights.
torch.hypot(input, other, *, out=None) → Tensor  
Given the legs of a right triangle, return its hypotenuse.  outi=inputi2+otheri2\text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}  
The shapes of input and other must be broadcastable.  Parameters 
 
input (Tensor) – the first input tensor 
other (Tensor) – the second input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.hypot(torch.tensor([4.0]), torch.tensor([3.0, 4.0, 5.0]))
tensor([5.0000, 5.6569, 6.4031])
torch.i0(input, *, out=None) → Tensor  
Computes the zeroth order modified Bessel function of the first kind for each element of input.  outi=I0(inputi)=∑k=0∞(inputi2/4)k(k!)2\text{out}_{i} = I_0(\text{input}_{i}) = \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!)^2}  
 Parameters 
input (Tensor) – the input tensor  Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> torch.i0(torch.arange(5, dtype=torch.float32))
tensor([ 1.0000,  1.2661,  2.2796,  4.8808, 11.3019])
torch.igamma(input, other, *, out=None) → Tensor  
Computes the regularized lower incomplete gamma function:  outi=1Γ(inputi)∫0otheritinputi−1e−tdt\text{out}_{i} = \frac{1}{\Gamma(\text{input}_i)} \int_0^{\text{other}_i} t^{\text{input}_i-1} e^{-t} dt  
where both inputi\text{input}_i  and otheri\text{other}_i  are weakly positive and at least one is strictly positive. If both are zero or either is negative then outi=nan\text{out}_i=\text{nan} . Γ(⋅)\Gamma(\cdot)  in the equation above is the gamma function,  Γ(inputi)=∫0∞t(inputi−1)e−tdt.\Gamma(\text{input}_i) = \int_0^\infty t^{(\text{input}_i-1)} e^{-t} dt.  
See torch.igammac() and torch.lgamma() for related functions. Supports broadcasting to a common shape and float inputs.  Note The backward pass with respect to input is not yet supported. Please open an issue on PyTorch’s Github to request it.   Parameters 
 
input (Tensor) – the first non-negative input tensor 
other (Tensor) – the second non-negative input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a1 = torch.tensor([4.0])
>>> a2 = torch.tensor([3.0, 4.0, 5.0])
>>> a = torch.igammac(a1, a2)
tensor([0.3528, 0.5665, 0.7350])
tensor([0.3528, 0.5665, 0.7350])
>>> b = torch.igamma(a1, a2) + torch.igammac(a1, a2)
tensor([1., 1., 1.])
torch.igammac(input, other, *, out=None) → Tensor  
Computes the regularized upper incomplete gamma function:  outi=1Γ(inputi)∫otheri∞tinputi−1e−tdt\text{out}_{i} = \frac{1}{\Gamma(\text{input}_i)} \int_{\text{other}_i}^{\infty} t^{\text{input}_i-1} e^{-t} dt  
where both inputi\text{input}_i  and otheri\text{other}_i  are weakly positive and at least one is strictly positive. If both are zero or either is negative then outi=nan\text{out}_i=\text{nan} . Γ(⋅)\Gamma(\cdot)  in the equation above is the gamma function,  Γ(inputi)=∫0∞t(inputi−1)e−tdt.\Gamma(\text{input}_i) = \int_0^\infty t^{(\text{input}_i-1)} e^{-t} dt.  
See torch.igamma() and torch.lgamma() for related functions. Supports broadcasting to a common shape and float inputs.  Note The backward pass with respect to input is not yet supported. Please open an issue on PyTorch’s Github to request it.   Parameters 
 
input (Tensor) – the first non-negative input tensor 
other (Tensor) – the second non-negative input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a1 = torch.tensor([4.0])
>>> a2 = torch.tensor([3.0, 4.0, 5.0])
>>> a = torch.igammac(a1, a2)
tensor([0.6472, 0.4335, 0.2650])
>>> b = torch.igamma(a1, a2) + torch.igammac(a1, a2)
tensor([1., 1., 1.])
torch.imag(input) → Tensor  
Returns a new tensor containing imaginary values of the self tensor. The returned tensor and self share the same underlying storage.  Warning imag() 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.imag
tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
torch.index_select(input, dim, index, *, out=None) → Tensor  
Returns a new tensor which indexes the input tensor along dimension dim using the entries in index which is a LongTensor. The returned tensor has the same number of dimensions as the original tensor (input). The dimth dimension has the same size as the length of index; other dimensions have the same size as in the original tensor.  Note The returned tensor does not use the same storage as the original tensor. If out has a different shape than expected, we silently change it to the correct shape, reallocating the underlying storage if necessary.   Parameters 
 
input (Tensor) – the input tensor. 
dim (int) – the dimension in which we index 
index (IntTensor or LongTensor) – the 1-D tensor containing the indices to index   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> x = torch.randn(3, 4)
>>> x
tensor([[ 0.1427,  0.0231, -0.5414, -1.0009],
        [-0.4664,  0.2647, -0.1228, -1.1068],
        [-1.1734, -0.6571,  0.7230, -0.6004]])
>>> indices = torch.tensor([0, 2])
>>> torch.index_select(x, 0, indices)
tensor([[ 0.1427,  0.0231, -0.5414, -1.0009],
        [-1.1734, -0.6571,  0.7230, -0.6004]])
>>> torch.index_select(x, 1, indices)
tensor([[ 0.1427, -0.5414],
        [-0.4664, -0.1228],
        [-1.1734,  0.7230]])
torch.initial_seed() [source]
 
Returns the initial seed for generating random numbers as a Python long.
torch.inner(input, other, *, out=None) → Tensor  
Computes the dot product for 1D tensors. For higher dimensions, sums the product of elements from input and other along their last dimension.  Note If either input or other is a scalar, the result is equivalent to torch.mul(input, other). If both input and other are non-scalars, the size of their last dimension must match and the result is equivalent to torch.tensordot(input, other, dims=([-1], [-1]))   Parameters 
 
input (Tensor) – First input tensor 
other (Tensor) – Second input tensor   Keyword Arguments 
out (Tensor, optional) – Optional output tensor to write result into. The output shape is input.shape[:-1] + other.shape[:-1].   Example: # Dot product
>>> torch.inner(torch.tensor([1, 2, 3]), torch.tensor([0, 2, 1]))
tensor(7)

# Multidimensional input tensors
>>> a = torch.randn(2, 3)
>>> a
tensor([[0.8173, 1.0874, 1.1784],
        [0.3279, 0.1234, 2.7894]])
>>> b = torch.randn(2, 4, 3)
>>> b
tensor([[[-0.4682, -0.7159,  0.1506],
        [ 0.4034, -0.3657,  1.0387],
        [ 0.9892, -0.6684,  0.1774],
        [ 0.9482,  1.3261,  0.3917]],

        [[ 0.4537,  0.7493,  1.1724],
        [ 0.2291,  0.5749, -0.2267],
        [-0.7920,  0.3607, -0.3701],
        [ 1.3666, -0.5850, -1.7242]]])
>>> torch.inner(a, b)
tensor([[[-0.9837,  1.1560,  0.2907,  2.6785],
        [ 2.5671,  0.5452, -0.6912, -1.5509]],

        [[ 0.1782,  2.9843,  0.7366,  1.5672],
        [ 3.5115, -0.4864, -1.2476, -4.4337]]])

# Scalar input
>>> torch.inner(a, torch.tensor(2))
tensor([[1.6347, 2.1748, 2.3567],
        [0.6558, 0.2469, 5.5787]])
torch.inverse(input, *, out=None) → Tensor  
Takes the inverse of the square matrix input. input can be batches of 2D square tensors, in which case this function would return a tensor composed of individual inverses. Supports real and complex input.  Note torch.inverse() is deprecated. Please use torch.linalg.inv() instead.   Note Irrespective of the original strides, the returned tensors will be transposed, i.e. with strides like input.contiguous().transpose(-2, -1).stride()   Parameters 
input (Tensor) – the input tensor of size (∗,n,n)(*, n, n)  where * is zero or more batch dimensions  Keyword Arguments 
out (Tensor, optional) – the output tensor.   Examples: >>> x = torch.rand(4, 4)
>>> y = torch.inverse(x)
>>> z = torch.mm(x, y)
>>> z
tensor([[ 1.0000, -0.0000, -0.0000,  0.0000],
        [ 0.0000,  1.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  1.0000,  0.0000],
        [ 0.0000, -0.0000, -0.0000,  1.0000]])
>>> torch.max(torch.abs(z - torch.eye(4))) # Max non-zero
tensor(1.1921e-07)

>>> # Batched inverse example
>>> x = torch.randn(2, 3, 4, 4)
>>> y = torch.inverse(x)
>>> z = torch.matmul(x, y)
>>> torch.max(torch.abs(z - torch.eye(4).expand_as(x))) # Max non-zero
tensor(1.9073e-06)

>>> x = torch.rand(4, 4, dtype=torch.cdouble)
>>> y = torch.inverse(x)
>>> z = torch.mm(x, y)
>>> z
tensor([[ 1.0000e+00+0.0000e+00j, -1.3878e-16+3.4694e-16j,
        5.5511e-17-1.1102e-16j,  0.0000e+00-1.6653e-16j],
        [ 5.5511e-16-1.6653e-16j,  1.0000e+00+6.9389e-17j,
        2.2204e-16-1.1102e-16j, -2.2204e-16+1.1102e-16j],
        [ 3.8858e-16-1.2490e-16j,  2.7756e-17+3.4694e-17j,
        1.0000e+00+0.0000e+00j, -4.4409e-16+5.5511e-17j],
        [ 4.4409e-16+5.5511e-16j, -3.8858e-16+1.8041e-16j,
        2.2204e-16+0.0000e+00j,  1.0000e+00-3.4694e-16j]],
    dtype=torch.complex128)
>>> torch.max(torch.abs(z - torch.eye(4, dtype=torch.cdouble))) # Max non-zero
tensor(7.5107e-16, dtype=torch.float64)
torch.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) → Tensor  
Returns a new tensor with boolean elements representing if each element of input is “close” to the corresponding element of other. Closeness is defined as:  ∣input−other∣≤atol+rtol×∣other∣\lvert \text{input} - \text{other} \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other} \rvert  
where input and other are finite. Where input and/or other are nonfinite they are close if and only if they are equal, with NaNs being considered equal to each other when equal_nan is True.  Parameters 
 
input (Tensor) – first tensor to compare 
other (Tensor) – second tensor to compare 
atol (float, optional) – absolute tolerance. Default: 1e-08 
rtol (float, optional) – relative tolerance. Default: 1e-05 
equal_nan (bool, optional) – if True, then two NaN s will be considered equal. Default: False
    Examples: >>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4)))
tensor([ True, False, False])
>>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5)
tensor([True, True])
torch.isfinite(input) → Tensor  
Returns a new tensor with boolean elements representing if each element is finite or not. Real values are finite when they are not NaN, negative infinity, or infinity. Complex values are finite when both their real and imaginary parts are finite.  Args:

input (Tensor): the input tensor.  Returns:

A boolean tensor that is True where input is finite and False elsewhere   Example: >>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([True,  False,  True,  False,  False])
torch.isinf(input) → Tensor  
Tests if each element of input is infinite (positive or negative infinity) or not.  Note Complex values are infinite when their real or imaginary part is infinite.  Args:

{input}  Returns:

A boolean tensor that is True where input is infinite and False elsewhere   Example: >>> torch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([False,  True,  False,  True,  False])
torch.isnan(input) → Tensor  
Returns a new tensor with boolean elements representing if each element of input is NaN or not. Complex values are considered NaN when either their real and/or imaginary part is NaN.  Parameters 
input (Tensor) – the input tensor.  Returns 
A boolean tensor that is True where input is NaN and False elsewhere   Example: >>> torch.isnan(torch.tensor([1, float('nan'), 2]))
tensor([False, True, False])
torch.isneginf(input, *, out=None) → Tensor  
Tests if each element of input is negative infinity or not.  Parameters 
input (Tensor) – the input tensor.  Keyword Arguments 
out (Tensor, optional) – the output tensor.    Example::

>>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
>>> torch.isneginf(a)
tensor([ True, False, False])
torch.isposinf(input, *, out=None) → Tensor  
Tests if each element of input is positive infinity or not.  Parameters 
input (Tensor) – the input tensor.  Keyword Arguments 
out (Tensor, optional) – the output tensor.    Example::

>>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
>>> torch.isposinf(a)
tensor([False,  True, False])
torch.isreal(input) → Tensor  
Returns a new tensor with boolean elements representing if each element of input is real-valued or not. All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.  Parameters 
input (Tensor) – the input tensor.  Returns 
A boolean tensor that is True where input is real and False elsewhere   Example: >>> torch.isreal(torch.tensor([1, 1+1j, 2+0j]))
tensor([True, False, True])
torch.istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False) [source]
 
Inverse short time Fourier Transform. This is expected to be the inverse of stft(). It has the same parameters (+ additional optional parameter of length) and it should return the least squares estimation of the original signal. The algorithm will check using the NOLA condition ( nonzero overlap). Important consideration in the parameters window and center so that the envelop created by the summation of all the windows is never zero at certain point in time. Specifically, ∑t=−∞∞∣w∣2[n−t×hop_length]=0\sum_{t=-\infty}^{\infty} |w|^2[n-t\times hop\_length] \cancel{=} 0 . Since stft() discards elements at the end of the signal if they do not fit in a frame, istft may return a shorter signal than the original signal (can occur if center is False since the signal isn’t padded). If center is True, then there will be padding e.g. 'constant', 'reflect', etc. Left padding can be trimmed off exactly because they can be calculated but right padding cannot be calculated without additional information. Example: Suppose the last window is: [17, 18, 0, 0, 0] vs [18, 0, 0, 0, 0] The n_fft, hop_length, win_length are all the same which prevents the calculation of right padding. These additional values could be zeros or a reflection of the signal so providing length could be useful. If length is None then padding will be aggressively removed (some loss of signal). [1] D. W. Griffin and J. S. Lim, “Signal estimation from modified short-time Fourier transform,” IEEE Trans. ASSP, vol.32, no.2, pp.236-243, Apr. 1984.  Parameters 
 
input (Tensor) – 
The input tensor. Expected to be output of stft(), can either be complex (channel, fft_size, n_frame), or real (channel, fft_size, n_frame, 2) where the channel dimension is optional.  Deprecated since version 1.8.0: Real input is deprecated, use complex inputs as returned by stft(..., return_complex=True) instead.   
n_fft (int) – Size of Fourier transform 
hop_length (Optional[int]) – The distance between neighboring sliding window frames. (Default: n_fft // 4) 
win_length (Optional[int]) – The size of window frame and STFT filter. (Default: n_fft) 
window (Optional[torch.Tensor]) – The optional window function. (Default: torch.ones(win_length)) 
center (bool) – Whether input was padded on both sides so that the tt -th frame is centered at time t×hop_lengtht \times \text{hop\_length} . (Default: True) 
normalized (bool) – Whether the STFT was normalized. (Default: False) 
onesided (Optional[bool]) – Whether the STFT was onesided. (Default: True if n_fft != fft_size in the input size) 
length (Optional[int]) – The amount to trim the signal by (i.e. the original signal length). (Default: whole signal) 
return_complex (Optional[bool]) – Whether the output should be complex, or if the input should be assumed to derive from a real signal and window. Note that this is incompatible with onesided=True. (Default: False)   Returns 
Least squares estimation of the original signal of size (…, signal_length)  Return type 
Tensor
torch.is_complex(input) -> (bool)  
Returns True if the data type of input is a complex data type i.e., one of torch.complex64, and torch.complex128.  Parameters 
input (Tensor) – the input tensor.
torch.is_floating_point(input) -> (bool)  
Returns True if the data type of input is a floating point data type i.e., one of torch.float64, torch.float32, torch.float16, and torch.bfloat16.  Parameters 
input (Tensor) – the input tensor.
torch.is_nonzero(input) -> (bool)  
Returns True if the input is a single element tensor which is not equal to zero after type conversions. i.e. not equal to torch.tensor([0.]) or torch.tensor([0]) or torch.tensor([False]). Throws a RuntimeError if torch.numel() != 1 (even in case of sparse tensors).  Parameters 
input (Tensor) – the input tensor.   Examples: >>> torch.is_nonzero(torch.tensor([0.]))
False
>>> torch.is_nonzero(torch.tensor([1.5]))
True
>>> torch.is_nonzero(torch.tensor([False]))
False
>>> torch.is_nonzero(torch.tensor([3]))
True
>>> torch.is_nonzero(torch.tensor([1, 3, 5]))
Traceback (most recent call last):
...
RuntimeError: bool value of Tensor with more than one value is ambiguous
>>> torch.is_nonzero(torch.tensor([]))
Traceback (most recent call last):
...
RuntimeError: bool value of Tensor with no values is ambiguous
torch.is_storage(obj) [source]
 
Returns True if obj is a PyTorch storage object.  Parameters 
obj (Object) – Object to test
torch.is_tensor(obj) [source]
 
Returns True if obj is a PyTorch tensor. Note that this function is simply doing isinstance(obj, Tensor). Using that isinstance check is better for typechecking with mypy, and more explicit - so it’s recommended to use that instead of is_tensor.  Parameters 
obj (Object) – Object to test
torch.jit.export(fn) [source]
 
This decorator indicates that a method on an nn.Module is used as an entry point into a ScriptModule and should be compiled. forward implicitly is assumed to be an entry point, so it does not need this decorator. Functions and methods called from forward are compiled as they are seen by the compiler, so they do not need this decorator either. Example (using @torch.jit.export on a method): import torch
import torch.nn as nn

class MyModule(nn.Module):
    def implicitly_compiled_method(self, x):
        return x + 99

    # `forward` is implicitly decorated with `@torch.jit.export`,
    # so adding it here would have no effect
    def forward(self, x):
        return x + 10

    @torch.jit.export
    def another_forward(self, x):
        # When the compiler sees this call, it will compile
        # `implicitly_compiled_method`
        return self.implicitly_compiled_method(x)

    def unused_method(self, x):
        return x - 20

# `m` will contain compiled methods:
#     `forward`
#     `another_forward`
#     `implicitly_compiled_method`
# `unused_method` will not be compiled since it was not called from
# any compiled methods and wasn't decorated with `@torch.jit.export`
m = torch.jit.script(MyModule())