neulab/docprompting-conala huggingface dataset:
torch.autograd.gradgradcheck(func, inputs, grad_outputs=None, eps=1e-06, atol=1e-05, rtol=0.001, gen_non_contig_grad_outputs=False, raise_exception=True, nondet_tol=0.0, check_undefined_grad=True, check_grad_dtypes=False, check_batched_grad=False) [source]
 
Check gradients of gradients computed via small finite differences against analytical gradients w.r.t. tensors in inputs and grad_outputs that are of floating point or complex type and with requires_grad=True. This function checks that backpropagating through the gradients computed to the given grad_outputs are correct. The check between numerical and analytical gradients uses allclose().  Note The default values are designed for input and grad_outputs of double precision. This check will likely fail if they are of less precision, e.g., FloatTensor.   Warning If any checked tensor in input and grad_outputs has overlapping memory, i.e., different indices pointing to the same memory address (e.g., from torch.expand()), this check will likely fail because the numerical gradients computed by point perturbation at such indices will change values at all other indices that share the same memory address.   Parameters 
 
func (function) – a Python function that takes Tensor inputs and returns a Tensor or a tuple of Tensors 
inputs (tuple of Tensor or Tensor) – inputs to the function 
grad_outputs (tuple of Tensor or Tensor, optional) – The gradients with respect to the function’s outputs. 
eps (float, optional) – perturbation for finite differences 
atol (float, optional) – absolute tolerance 
rtol (float, optional) – relative tolerance 
gen_non_contig_grad_outputs (bool, optional) – if grad_outputs is None and gen_non_contig_grad_outputs is True, the randomly generated gradient outputs are made to be noncontiguous 
raise_exception (bool, optional) – indicating whether to raise an exception if the check fails. The exception gives more information about the exact nature of the failure. This is helpful when debugging gradchecks. 
nondet_tol (float, optional) – tolerance for non-determinism. When running identical inputs through the differentiation, the results must either match exactly (default, 0.0) or be within this tolerance. Note that a small amount of nondeterminism in the gradient will lead to larger inaccuracies in the second derivative. 
check_undefined_grad (bool, optional) – if True, check if undefined output grads are supported and treated as zeros 
check_batched_grad (bool, optional) – if True, check if we can compute batched gradients using prototype vmap support. Defaults to False.   Returns 
True if all differences satisfy allclose condition
class torch.autograd.no_grad [source]
 
Context-manager that disabled gradient calculation. Disabling gradient calculation is useful for inference, when you are sure that you will not call Tensor.backward(). It will reduce memory consumption for computations that would otherwise have requires_grad=True. In this mode, the result of every computation will have requires_grad=False, even when the inputs have requires_grad=True. This context manager is thread local; it will not affect computation in other threads. Also functions as a decorator. (Make sure to instantiate with parenthesis.) Example: >>> x = torch.tensor([1], requires_grad=True)
>>> with torch.no_grad():
...   y = x * 2
>>> y.requires_grad
False
>>> @torch.no_grad()
... def doubler(x):
...     return x * 2
>>> z = doubler(x)
>>> z.requires_grad
False
torch.autograd.profiler.load_nvprof(path) [source]
 
Opens an nvprof trace file and parses autograd annotations.  Parameters 
path (str) – path to nvprof trace
export_chrome_trace(path) [source]
 
Exports an EventList as a Chrome tracing tools file. The checkpoint can be later loaded and inspected under chrome://tracing URL.  Parameters 
path (str) – Path where the trace will be written.
key_averages(group_by_input_shape=False, group_by_stack_n=0) [source]
 
Averages all function events over their keys.  Parameters 
 
group_by_input_shapes – group entries by 
name, input shapes) rather than just event name. ((event) –  
is useful to see which input shapes contribute to the runtime (This) –  
most and may help with size-specific optimizations or (the) –  
the best candidates for quantization (choosing) –  
group_by_stack_n – group by top n stack trace entries   Returns 
An EventList containing FunctionEventAvg objects.
property self_cpu_time_total  
Returns total time spent on CPU obtained as a sum of all self times across all the events.
table(sort_by=None, row_limit=100, max_src_column_width=75, header=None, top_level_events_only=False) [source]
 
Prints an EventList as a nicely formatted table.  Parameters 
 
sort_by (str, optional) – Attribute used to sort entries. By default they are printed in the same order as they were registered. Valid keys include: cpu_time, cuda_time, cpu_time_total, cuda_time_total, cpu_memory_usage, cuda_memory_usage, self_cpu_memory_usage, self_cuda_memory_usage, count. 
top_level_events_only (bool, optional) – Boolean flag to determine the selection of events to display. If true, the profiler will only display events at top level like top-level invocation of python lstm, python add or other functions, nested events like low-level cpu/cuda ops events are omitted for profiler result readability.   Returns 
A string containing the table.
total_average() [source]
 
Averages all events.  Returns 
A FunctionEventAvg object.
class torch.autograd.set_detect_anomaly(mode) [source]
 
Context-manager that sets the anomaly detection for the autograd engine on or off. set_detect_anomaly will enable or disable the autograd anomaly detection based on its argument mode. It can be used as a context-manager or as a function. See detect_anomaly above for details of the anomaly detection behaviour.  Parameters 
mode (bool) – Flag whether to enable anomaly detection (True), or disable (False).
class torch.autograd.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.backends torch.backends controls the behavior of various backends that PyTorch supports. These backends include:  torch.backends.cuda torch.backends.cudnn torch.backends.mkl torch.backends.mkldnn torch.backends.openmp  torch.backends.cuda  
torch.backends.cuda.is_built() [source]
 
Returns whether PyTorch is built with CUDA support. Note that this doesn’t necessarily mean CUDA is available; just that if this PyTorch binary were run a machine with working CUDA drivers and devices, we would be able to use it. 
  
torch.backends.cuda.matmul.allow_tf32  
A bool that controls whether TensorFloat-32 tensor cores may be used in matrix multiplications on Ampere or newer GPUs. See TensorFloat-32(TF32) on Ampere devices. 
  
torch.backends.cuda.cufft_plan_cache  
cufft_plan_cache caches the cuFFT plans  
size  
A readonly int that shows the number of plans currently in the cuFFT plan cache. 
  
max_size  
A int that controls cache capacity of cuFFT plan. 
  
clear()  
Clears the cuFFT plan cache. 
 
 torch.backends.cudnn  
torch.backends.cudnn.version() [source]
 
Returns the version of cuDNN 
  
torch.backends.cudnn.is_available() [source]
 
Returns a bool indicating if CUDNN is currently available. 
  
torch.backends.cudnn.enabled  
A bool that controls whether cuDNN is enabled. 
  
torch.backends.cudnn.allow_tf32  
A bool that controls where TensorFloat-32 tensor cores may be used in cuDNN convolutions on Ampere or newer GPUs. See TensorFloat-32(TF32) on Ampere devices. 
  
torch.backends.cudnn.deterministic  
A bool that, if True, causes cuDNN to only use deterministic convolution algorithms. See also torch.are_deterministic_algorithms_enabled() and torch.use_deterministic_algorithms(). 
  
torch.backends.cudnn.benchmark  
A bool that, if True, causes cuDNN to benchmark multiple convolution algorithms and select the fastest. 
 torch.backends.mkl  
torch.backends.mkl.is_available() [source]
 
Returns whether PyTorch is built with MKL support. 
 torch.backends.mkldnn  
torch.backends.mkldnn.is_available() [source]
 
Returns whether PyTorch is built with MKL-DNN support. 
 torch.backends.openmp  
torch.backends.openmp.is_available() [source]
 
Returns whether PyTorch is built with OpenMP support.
torch.backends.cuda.cufft_plan_cache  
cufft_plan_cache caches the cuFFT plans  
size  
A readonly int that shows the number of plans currently in the cuFFT plan cache. 
  
max_size  
A int that controls cache capacity of cuFFT plan. 
  
clear()  
Clears the cuFFT plan cache.
torch.backends.cuda.is_built() [source]
 
Returns whether PyTorch is built with CUDA support. Note that this doesn’t necessarily mean CUDA is available; just that if this PyTorch binary were run a machine with working CUDA drivers and devices, we would be able to use it.
torch.backends.cuda.matmul.allow_tf32  
A bool that controls whether TensorFloat-32 tensor cores may be used in matrix multiplications on Ampere or newer GPUs. See TensorFloat-32(TF32) on Ampere devices.
size  
A readonly int that shows the number of plans currently in the cuFFT plan cache.
torch.backends.cudnn.allow_tf32  
A bool that controls where TensorFloat-32 tensor cores may be used in cuDNN convolutions on Ampere or newer GPUs. See TensorFloat-32(TF32) on Ampere devices.
torch.backends.cudnn.benchmark  
A bool that, if True, causes cuDNN to benchmark multiple convolution algorithms and select the fastest.
torch.backends.cudnn.deterministic  
A bool that, if True, causes cuDNN to only use deterministic convolution algorithms. See also torch.are_deterministic_algorithms_enabled() and torch.use_deterministic_algorithms().
torch.backends.cudnn.enabled  
A bool that controls whether cuDNN is enabled.
torch.backends.cudnn.is_available() [source]
 
Returns a bool indicating if CUDNN is currently available.
torch.backends.cudnn.version() [source]
 
Returns the version of cuDNN
torch.backends.mkl.is_available() [source]
 
Returns whether PyTorch is built with MKL support.
torch.backends.mkldnn.is_available() [source]
 
Returns whether PyTorch is built with MKL-DNN support.
torch.backends.openmp.is_available() [source]
 
Returns whether PyTorch is built with OpenMP support.
torch.baddbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) → Tensor  
Performs a batch matrix-matrix product of matrices in batch1 and batch2. input is added to the final result. batch1 and batch2 must be 3-D tensors each containing the same number of matrices. If batch1 is a (b×n×m)(b \times n \times m)  tensor, batch2 is a (b×m×p)(b \times m \times p)  tensor, then input must be broadcastable with a (b×n×p)(b \times n \times p)  tensor and out will be a (b×n×p)(b \times n \times p)  tensor. Both alpha and beta mean the same as the scaling factors used in torch.addbmm().  outi=βinputi+α(batch1i@batch2i)\text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)  
If beta is 0, then input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. This operator supports TensorFloat32.  Parameters 
 
input (Tensor) – the tensor to be added 
batch1 (Tensor) – the first batch of matrices to be multiplied 
batch2 (Tensor) – the second batch of matrices to be multiplied   Keyword Arguments 
 
beta (Number, optional) – multiplier for input (β\beta ) 
alpha (Number, optional) – multiplier for batch1@batch2\text{batch1} \mathbin{@} \text{batch2}  (α\alpha ) 
out (Tensor, optional) – the output tensor.    Example: >>> M = torch.randn(10, 3, 5)
>>> batch1 = torch.randn(10, 3, 4)
>>> batch2 = torch.randn(10, 4, 5)
>>> torch.baddbmm(M, batch1, batch2).size()
torch.Size([10, 3, 5])
torch.bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor  
Bartlett window function.  w[n]=1−∣2nN−1−1∣={2nN−1if 0≤n≤N−122−2nN−1if N−12<n<N,w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases} \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\ 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\ \end{cases},  
where NN  is the full window size. The input window_length is a positive integer controlling the returned window size. periodic flag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions like torch.stft(). Therefore, if periodic is true, the NN  in above formula is in fact window_length+1\text{window\_length} + 1 . Also, we always have torch.bartlett_window(L, periodic=True) equal to torch.bartlett_window(L + 1, periodic=False)[:-1]).  Note If window_length =1=1 , the returned window contains a single value 1.   Parameters 
 
window_length (int) – the size of returned window 
periodic (bool, optional) – If True, returns a window to be used as periodic function. If False, return a symmetric window.   Keyword Arguments 
 
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()). Only floating point types are supported. 
layout (torch.layout, optional) – the desired layout of returned window tensor. Only torch.strided (dense layout) is supported. 
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.   Returns 
A 1-D tensor of size (window_length,)(\text{window\_length},)  containing the window  Return type 
Tensor
torch.bernoulli(input, *, generator=None, out=None) → Tensor  
Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor containing probabilities to be used for drawing the binary random number. Hence, all values in input have to be in the range: 0≤inputi≤10 \leq \text{input}_i \leq 1 . The ith\text{i}^{th}  element of the output tensor will draw a value 11  according to the ith\text{i}^{th}  probability value given in input.  outi∼Bernoulli(p=inputi)\text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})  
The returned out tensor only has values 0 or 1 and is of the same shape as input. out can have integral dtype, but input must have floating point dtype.  Parameters 
input (Tensor) – the input tensor of probability values for the Bernoulli distribution  Keyword Arguments 
 
generator (torch.Generator, optional) – a pseudorandom number generator for sampling 
out (Tensor, optional) – the output tensor.    Example: >>> a = torch.empty(3, 3).uniform_(0, 1)  # generate a uniform random matrix with range [0, 1]
>>> a
tensor([[ 0.1737,  0.0950,  0.3609],
        [ 0.7148,  0.0289,  0.2676],
        [ 0.9456,  0.8937,  0.7202]])
>>> torch.bernoulli(a)
tensor([[ 1.,  0.,  0.],
        [ 0.,  0.,  0.],
        [ 1.,  1.,  1.]])

>>> a = torch.ones(3, 3) # probability of drawing "1" is 1
>>> torch.bernoulli(a)
tensor([[ 1.,  1.,  1.],
        [ 1.,  1.,  1.],
        [ 1.,  1.,  1.]])
>>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
>>> torch.bernoulli(a)
tensor([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])
torch.bincount(input, weights=None, minlength=0) → Tensor  
Count the frequency of each value in an array of non-negative ints. The number of bins (size 1) is one larger than the largest value in input unless input is empty, in which case the result is a tensor of size 0. If minlength is specified, the number of bins is at least minlength and if input is empty, then the result is tensor of size minlength filled with zeros. If n is the value at position i, out[n] += weights[i] if weights is specified else out[n] += 1.  Note This operation may produce nondeterministic gradients when given tensors on a CUDA device. See Reproducibility for more information.   Parameters 
 
input (Tensor) – 1-d int tensor 
weights (Tensor) – optional, weight for each value in the input tensor. Should be of same size as input tensor. 
minlength (int) – optional, minimum number of bins. Should be non-negative.   Returns 
a tensor of shape Size([max(input) + 1]) if input is non-empty, else Size(0)  Return type 
output (Tensor)   Example: >>> input = torch.randint(0, 8, (5,), dtype=torch.int64)
>>> weights = torch.linspace(0, 1, steps=5)
>>> input, weights
(tensor([4, 3, 6, 3, 4]),
 tensor([ 0.0000,  0.2500,  0.5000,  0.7500,  1.0000])

>>> torch.bincount(input)
tensor([0, 0, 0, 2, 2, 0, 1])

>>> input.bincount(weights)
tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
torch.bitwise_and(input, other, *, out=None) → Tensor  
Computes the bitwise AND of input and other. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical AND.  Parameters 
 
input – the first input tensor 
other – the second input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([1, 0,  3], dtype=torch.int8)
>>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ False, True, False])
torch.bitwise_not(input, *, out=None) → Tensor  
Computes the bitwise NOT of the given input tensor. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical NOT.  Parameters 
input (Tensor) – the input tensor.  Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example >>> torch.bitwise_not(torch.tensor([-1, -2, 3], dtype=torch.int8))
tensor([ 0,  1, -4], dtype=torch.int8)
torch.bitwise_or(input, other, *, out=None) → Tensor  
Computes the bitwise OR of input and other. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical OR.  Parameters 
 
input – the first input tensor 
other – the second input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-1, -2,  3], dtype=torch.int8)
>>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ True, True, False])
torch.bitwise_xor(input, other, *, out=None) → Tensor  
Computes the bitwise XOR of input and other. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical XOR.  Parameters 
 
input – the first input tensor 
other – the second input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-2, -2,  0], dtype=torch.int8)
>>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ True, False, False])
torch.blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor  
Blackman window function.  w[n]=0.42−0.5cos⁡(2πnN−1)+0.08cos⁡(4πnN−1)w[n] = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{N - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{N - 1} \right)  
where NN  is the full window size. The input window_length is a positive integer controlling the returned window size. periodic flag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions like torch.stft(). Therefore, if periodic is true, the NN  in above formula is in fact window_length+1\text{window\_length} + 1 . Also, we always have torch.blackman_window(L, periodic=True) equal to torch.blackman_window(L + 1, periodic=False)[:-1]).  Note If window_length =1=1 , the returned window contains a single value 1.   Parameters 
 
window_length (int) – the size of returned window 
periodic (bool, optional) – If True, returns a window to be used as periodic function. If False, return a symmetric window.   Keyword Arguments 
 
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()). Only floating point types are supported. 
layout (torch.layout, optional) – the desired layout of returned window tensor. Only torch.strided (dense layout) is supported. 
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.   Returns 
A 1-D tensor of size (window_length,)(\text{window\_length},)  containing the window  Return type 
Tensor
torch.block_diag(*tensors) [source]
 
Create a block diagonal matrix from provided tensors.  Parameters 
*tensors – One or more tensors with 0, 1, or 2 dimensions.  Returns 
 A 2 dimensional tensor with all the input tensors arranged in

order such that their upper left and lower right corners are diagonally adjacent. All other elements are set to 0.    Return type 
Tensor   Example: >>> import torch
>>> A = torch.tensor([[0, 1], [1, 0]])
>>> B = torch.tensor([[3, 4, 5], [6, 7, 8]])
>>> C = torch.tensor(7)
>>> D = torch.tensor([1, 2, 3])
>>> E = torch.tensor([[4], [5], [6]])
>>> torch.block_diag(A, B, C, D, E)
tensor([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 3, 4, 5, 0, 0, 0, 0, 0],
        [0, 0, 6, 7, 8, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 7, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 1, 2, 3, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 5],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 6]])
torch.bmm(input, mat2, *, deterministic=False, out=None) → Tensor  
Performs a batch matrix-matrix product of matrices stored in input and mat2. input and mat2 must be 3-D tensors each containing the same number of matrices. If input is a (b×n×m)(b \times n \times m)  tensor, mat2 is a (b×m×p)(b \times m \times p)  tensor, out will be a (b×n×p)(b \times n \times p)  tensor.  outi=inputi@mat2i\text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i  
This operator supports TensorFloat32.  Note This function does not broadcast. For broadcasting matrix products, see torch.matmul().   Parameters 
 
input (Tensor) – the first batch of matrices to be multiplied 
mat2 (Tensor) – the second batch of matrices to be multiplied   Keyword Arguments 
 
deterministic (bool, optional) – flag to choose between a faster non-deterministic calculation, or a slower deterministic calculation. This argument is only available for sparse-dense CUDA bmm. Default: False
 
out (Tensor, optional) – the output tensor.    Example: >>> input = torch.randn(10, 3, 4)
>>> mat2 = torch.randn(10, 4, 5)
>>> res = torch.bmm(input, mat2)
>>> res.size()
torch.Size([10, 3, 5])