neulab/docprompting-conala huggingface dataset:
create_args_for_root(root_fn, is_module, concrete_args=None) [source]
 
Create placeholder nodes corresponding to the signature of the root Module. This method introspects root’s signature and emits those nodes accordingly, also supporting *args and **kwargs.
is_leaf_module(m, module_qualified_name) [source]
 
A method to specify whether a given nn.Module is a “leaf” module. Leaf modules are the atomic units that appear in the IR, referenced by call_module calls. By default, Modules in the PyTorch standard library namespace (torch.nn) are leaf modules. All other modules are traced through and their constituent ops are recorded, unless specified otherwise via this parameter.  Parameters 
 
m (Module) – The module being queried about 
module_qualified_name (str) – The path to root of this module. For example, if you have a module hierarchy where submodule foo contains submodule bar, which contains submodule baz, that module will appear with the qualified name foo.bar.baz here.
path_of_module(mod) [source]
 
Helper method to find the qualified name of mod in the Module hierarchy of root. For example, if root has a submodule named foo, which has a submodule named bar, passing bar into this function will return the string “foo.bar”.  Parameters 
mod (str) – The Module to retrieve the qualified name for.
trace(root, concrete_args=None) [source]
 
Trace root and return the corresponding FX Graph representation. root can either be an nn.Module instance or a Python callable. Note that after this call, self.root may be different from the root passed in here. For example, when a free function is passed to trace(), we will create an nn.Module instance to use as the root and add embedded constants to.  Parameters 
root (Union[Module, Callable]) – Either a Module or a function to be traced through.  Returns 
A Graph representing the semantics of the passed-in root.
class torch.fx.Transformer(module) [source]
 
Transformer is a special type of interpreter that produces a new Module. It exposes a transform() method that returns the transformed Module. Transformer does not require arguments to run, as Interpreter does. Transformer works entirely symbolically. Example Suppose we want to swap all instances of torch.neg with torch.sigmoid and vice versa (including their Tensor method equivalents). We could subclass Transformer like so: class NegSigmSwapXformer(Transformer):
    def call_function(self, target : 'Target', args : Tuple[Argument, ...], kwargs : Dict[str, Any]) -> Any:
        if target == torch.sigmoid:
            return torch.neg(*args, **kwargs)
        return super().call_function(n)

    def call_method(self, target : 'Target', args : Tuple[Argument, ...], kwargs : Dict[str, Any]) -> Any:
        if target == 'neg':
            call_self, *args_tail = args
            return call_self.sigmoid(*args_tail, **kwargs)
        return super().call_method(n)

def fn(x):
    return torch.sigmoid(x).neg()

gm = torch.fx.symbolic_trace(fn)

transformed : torch.nn.Module = NegSigmSwapXformer(gm).transform()
input = torch.randn(3, 4)
torch.testing.assert_allclose(transformed(input), torch.neg(input).sigmoid())
  Parameters 
module (GraphModule) – The Module to be transformed.    
get_attr(target, args, kwargs) [source]
 
Execute a get_attr node. In Transformer, this is overridden to insert a new get_attr node into the output graph.  Parameters 
 
target (Target) – The call target for this node. See Node for details on semantics 
args (Tuple) – Tuple of positional args for this invocation 
kwargs (Dict) – Dict of keyword arguments for this invocation    
  
placeholder(target, args, kwargs) [source]
 
Execute a placeholder node. In Transformer, this is overridden to insert a new placeholder into the output graph.  Parameters 
 
target (Target) – The call target for this node. See Node for details on semantics 
args (Tuple) – Tuple of positional args for this invocation 
kwargs (Dict) – Dict of keyword arguments for this invocation    
  
transform() [source]
 
Transform self.module and return the transformed GraphModule.
get_attr(target, args, kwargs) [source]
 
Execute a get_attr node. In Transformer, this is overridden to insert a new get_attr node into the output graph.  Parameters 
 
target (Target) – The call target for this node. See Node for details on semantics 
args (Tuple) – Tuple of positional args for this invocation 
kwargs (Dict) – Dict of keyword arguments for this invocation
placeholder(target, args, kwargs) [source]
 
Execute a placeholder node. In Transformer, this is overridden to insert a new placeholder into the output graph.  Parameters 
 
target (Target) – The call target for this node. See Node for details on semantics 
args (Tuple) – Tuple of positional args for this invocation 
kwargs (Dict) – Dict of keyword arguments for this invocation
torch.fx.wrap(fn_or_name) [source]
 
This function can be called at module-level scope to register fn_or_name as a “leaf function”. A “leaf function” will be preserved as a CallFunction node in the FX trace instead of being traced through: # foo/bar/baz.py
def my_custom_function(x, y):
    return x * x + y * y

torch.fx.wrap('my_custom_function')

def fn_to_be_traced(x, y):
    # When symbolic tracing, the below call to my_custom_function will be inserted into
    # the graph rather than tracing it.
    return my_custom_function(x, y)
 This function can also equivalently be used as a decorator: # foo/bar/baz.py
@torch.fx.wrap
def my_custom_function(x, y):
    return x * x + y * y
 A wrapped function can be thought of a “leaf function”, analogous to the concept of “leaf modules”, that is, they are functions that are left as calls in the FX trace rather than traced through.  Parameters 
fn_or_name (Union[str, Callable]) – The function or name of the global function to insert into the graph when it’s called
torch.gather(input, dim, index, *, sparse_grad=False, out=None) → Tensor  
Gathers values along an axis specified by dim. For a 3-D tensor the output is specified by: out[i][j][k] = input[index[i][j][k]][j][k]  # if dim == 0
out[i][j][k] = input[i][index[i][j][k]][k]  # if dim == 1
out[i][j][k] = input[i][j][index[i][j][k]]  # if dim == 2
 input and index must have the same number of dimensions. It is also required that index.size(d) <= input.size(d) for all dimensions d != dim. out will have the same shape as index. Note that input and index do not broadcast against each other.  Parameters 
 
input (Tensor) – the source tensor 
dim (int) – the axis along which to index 
index (LongTensor) – the indices of elements to gather   Keyword Arguments 
 
sparse_grad (bool, optional) – If True, gradient w.r.t. input will be a sparse tensor. 
out (Tensor, optional) – the destination tensor    Example: >>> t = torch.tensor([[1, 2], [3, 4]])
>>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
tensor([[ 1,  1],
        [ 4,  3]])
torch.gcd(input, other, *, out=None) → Tensor  
Computes the element-wise greatest common divisor (GCD) of input and other. Both input and other must have integer types.  Note This defines gcd(0,0)=0gcd(0, 0) = 0 .   Parameters 
 
input (Tensor) – the input tensor. 
other (Tensor) – the second input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.tensor([5, 10, 15])
>>> b = torch.tensor([3, 4, 5])
>>> torch.gcd(a, b)
tensor([1, 2, 5])
>>> c = torch.tensor([3])
>>> torch.gcd(a, c)
tensor([1, 1, 3])
torch.ge(input, other, *, out=None) → Tensor  
Computes input≥other\text{input} \geq \text{other}  element-wise. The second argument can be a number or a tensor whose shape is broadcastable with the first argument.  Parameters 
 
input (Tensor) – the tensor to compare 
other (Tensor or float) – the tensor or value to compare   Keyword Arguments 
out (Tensor, optional) – the output tensor.  Returns 
A boolean tensor that is True where input is greater than or equal to other and False elsewhere   Example: >>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[True, True], [False, True]])
class torch.Generator(device='cpu') → Generator  
Creates and returns a generator object that manages the state of the algorithm which produces pseudo random numbers. Used as a keyword argument in many In-place random sampling functions.  Parameters 
device (torch.device, optional) – the desired device for the generator.  Returns 
An torch.Generator object.  Return type 
Generator   Example: >>> g_cpu = torch.Generator()
>>> g_cuda = torch.Generator(device='cuda')
  
device  
Generator.device -> device Gets the current device of the generator. Example: >>> g_cpu = torch.Generator()
>>> g_cpu.device
device(type='cpu')
 
  
get_state() → Tensor  
Returns the Generator state as a torch.ByteTensor.  Returns 
A torch.ByteTensor which contains all the necessary bits to restore a Generator to a specific point in time.  Return type 
Tensor   Example: >>> g_cpu = torch.Generator()
>>> g_cpu.get_state()
 
  
initial_seed() → int  
Returns the initial seed for generating random numbers. Example: >>> g_cpu = torch.Generator()
>>> g_cpu.initial_seed()
2147483647
 
  
manual_seed(seed) → Generator  
Sets the seed for generating random numbers. Returns a torch.Generator object. It is recommended to set a large seed, i.e. a number that has a good balance of 0 and 1 bits. Avoid having many 0 bits in the seed.  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.  Returns 
An torch.Generator object.  Return type 
Generator   Example: >>> g_cpu = torch.Generator()
>>> g_cpu.manual_seed(2147483647)
 
  
seed() → int  
Gets a non-deterministic random number from std::random_device or the current time and uses it to seed a Generator. Example: >>> g_cpu = torch.Generator()
>>> g_cpu.seed()
1516516984916
 
  
set_state(new_state) → void  
Sets the Generator state.  Parameters 
new_state (torch.ByteTensor) – The desired state.   Example: >>> g_cpu = torch.Generator()
>>> g_cpu_other = torch.Generator()
>>> g_cpu.set_state(g_cpu_other.get_state())
device  
Generator.device -> device Gets the current device of the generator. Example: >>> g_cpu = torch.Generator()
>>> g_cpu.device
device(type='cpu')
get_state() → Tensor  
Returns the Generator state as a torch.ByteTensor.  Returns 
A torch.ByteTensor which contains all the necessary bits to restore a Generator to a specific point in time.  Return type 
Tensor   Example: >>> g_cpu = torch.Generator()
>>> g_cpu.get_state()
initial_seed() → int  
Returns the initial seed for generating random numbers. Example: >>> g_cpu = torch.Generator()
>>> g_cpu.initial_seed()
2147483647
manual_seed(seed) → Generator  
Sets the seed for generating random numbers. Returns a torch.Generator object. It is recommended to set a large seed, i.e. a number that has a good balance of 0 and 1 bits. Avoid having many 0 bits in the seed.  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.  Returns 
An torch.Generator object.  Return type 
Generator   Example: >>> g_cpu = torch.Generator()
>>> g_cpu.manual_seed(2147483647)
seed() → int  
Gets a non-deterministic random number from std::random_device or the current time and uses it to seed a Generator. Example: >>> g_cpu = torch.Generator()
>>> g_cpu.seed()
1516516984916
set_state(new_state) → void  
Sets the Generator state.  Parameters 
new_state (torch.ByteTensor) – The desired state.   Example: >>> g_cpu = torch.Generator()
>>> g_cpu_other = torch.Generator()
>>> g_cpu.set_state(g_cpu_other.get_state())
torch.geqrf(input, *, out=None) -> (Tensor, Tensor)  
This is a low-level function for calling LAPACK directly. This function returns a namedtuple (a, tau) as defined in LAPACK documentation for geqrf . You’ll generally want to use torch.qr() instead. Computes a QR decomposition of input, but without constructing QQ  and RR  as explicit separate matrices. Rather, this directly calls the underlying LAPACK function ?geqrf which produces a sequence of ‘elementary reflectors’. See LAPACK documentation for geqrf for further details.  Parameters 
input (Tensor) – the input matrix  Keyword Arguments 
out (tuple, optional) – the output tuple of (Tensor, Tensor)
torch.ger(input, vec2, *, out=None) → Tensor  
Alias of torch.outer().  Warning This function is deprecated and will be removed in a future PyTorch release. Use torch.outer() instead.
torch.get_default_dtype() → torch.dtype  
Get the current default floating point torch.dtype. Example: >>> torch.get_default_dtype()  # initial default for floating point is torch.float32
torch.float32
>>> torch.set_default_dtype(torch.float64)
>>> torch.get_default_dtype()  # default is now changed to torch.float64
torch.float64
>>> torch.set_default_tensor_type(torch.FloatTensor)  # setting tensor type also affects this
>>> torch.get_default_dtype()  # changed to torch.float32, the dtype for torch.FloatTensor
torch.float32
torch.get_num_interop_threads() → int  
Returns the number of threads used for inter-op parallelism on CPU (e.g. in JIT interpreter)
torch.get_num_threads() → int  
Returns the number of threads used for parallelizing CPU operations
torch.get_rng_state() [source]
 
Returns the random number generator state as a torch.ByteTensor.
torch.greater(input, other, *, out=None) → Tensor  
Alias for torch.gt().
torch.greater_equal(input, other, *, out=None) → Tensor  
Alias for torch.ge().
torch.gt(input, other, *, out=None) → Tensor  
Computes input>other\text{input} > \text{other}  element-wise. The second argument can be a number or a tensor whose shape is broadcastable with the first argument.  Parameters 
 
input (Tensor) – the tensor to compare 
other (Tensor or float) – the tensor or value to compare   Keyword Arguments 
out (Tensor, optional) – the output tensor.  Returns 
A boolean tensor that is True where input is greater than other and False elsewhere   Example: >>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[False, True], [False, False]])
torch.hamming_window(window_length, periodic=True, alpha=0.54, beta=0.46, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor  
Hamming window function.  w[n]=α−βcos⁡(2πnN−1),w[n] = \alpha - \beta\ \cos \left( \frac{2 \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.hamming_window(L, periodic=True) equal to torch.hamming_window(L + 1, periodic=False)[:-1]).  Note If window_length =1=1 , the returned window contains a single value 1.   Note This is a generalized version of torch.hann_window().   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. 
alpha (float, optional) – The coefficient α\alpha  in the equation above 
beta (float, optional) – The coefficient β\beta  in the equation above   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.hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor  
Hann window function.  w[n]=12[1−cos⁡(2πnN−1)]=sin⁡2(πnN−1),w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] = \sin^2 \left( \frac{\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.hann_window(L, periodic=True) equal to torch.hann_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.heaviside(input, values, *, out=None) → Tensor  
Computes the Heaviside step function for each element in input. The Heaviside step function is defined as:  heaviside(input,values)={0,if input < 0values,if input == 01,if input > 0\text{{heaviside}}(input, values) = \begin{cases} 0, & \text{if input < 0}\\ values, & \text{if input == 0}\\ 1, & \text{if input > 0} \end{cases}  
 Parameters 
 
input (Tensor) – the input tensor. 
values (Tensor) – The values to use where input is zero.   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> input = torch.tensor([-1.5, 0, 2.0])
>>> values = torch.tensor([0.5])
>>> torch.heaviside(input, values)
tensor([0.0000, 0.5000, 1.0000])
>>> values = torch.tensor([1.2, -2.0, 3.5])
>>> torch.heaviside(input, values)
tensor([0., -2., 1.])
torch.histc(input, bins=100, min=0, max=0, *, out=None) → Tensor  
Computes the histogram of a tensor. The elements are sorted into equal width bins between min and max. If min and max are both zero, the minimum and maximum values of the data are used. Elements lower than min and higher than max are ignored.  Parameters 
 
input (Tensor) – the input tensor. 
bins (int) – number of histogram bins 
min (int) – lower end of the range (inclusive) 
max (int) – upper end of the range (inclusive)   Keyword Arguments 
out (Tensor, optional) – the output tensor.  Returns 
Histogram represented as a tensor  Return type 
Tensor   Example: >>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)
tensor([ 0.,  2.,  1.,  0.])
torch.hspmm(mat1, mat2, *, out=None) → Tensor  
Performs a matrix multiplication of a sparse COO matrix mat1 and a strided matrix mat2. The result is a (1 + 1)-dimensional hybrid COO matrix.  Parameters 
 
mat1 (Tensor) – the first sparse matrix to be matrix multiplied 
mat2 (Tensor) – the second strided matrix to be matrix multiplied   Keyword Arguments 
{out} –
torch.hstack(tensors, *, out=None) → Tensor  
Stack tensors in sequence horizontally (column wise). This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.  Parameters 
tensors (sequence of Tensors) – sequence of tensors to concatenate  Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.hstack((a,b))
tensor([1, 2, 3, 4, 5, 6])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.hstack((a,b))
tensor([[1, 4],
        [2, 5],
        [3, 6]])
torch.hub.download_url_to_file(url, dst, hash_prefix=None, progress=True) [source]
 
Download object at the given URL to a local path.  Parameters 
 
url (string) – URL of the object to download 
dst (string) – Full path where object will be saved, e.g. /tmp/temporary_file
 
hash_prefix (string, optional) – If not None, the SHA256 downloaded file should start with hash_prefix. Default: None 
progress (bool, optional) – whether or not to display a progress bar to stderr Default: True    Example >>> torch.hub.download_url_to_file('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth', '/tmp/temporary_file')
torch.hub.get_dir() [source]
 
Get the Torch Hub cache directory used for storing downloaded models & weights. If set_dir() is not called, default path is $TORCH_HOME/hub where environment variable $TORCH_HOME defaults to $XDG_CACHE_HOME/torch. $XDG_CACHE_HOME follows the X Design Group specification of the Linux filesystem layout, with a default value ~/.cache if the environment variable is not set.
torch.hub.help(github, model, force_reload=False) [source]
 
Show the docstring of entrypoint model.  Parameters 
 
github (string) – a string with format <repo_owner/repo_name[:tag_name]> with an optional tag/branch. The default branch is master if not specified. Example: ‘pytorch/vision[:hub]’ 
model (string) – a string of entrypoint name defined in repo’s hubconf.py 
force_reload (bool, optional) – whether to discard the existing cache and force a fresh download. Default is False.    Example >>> print(torch.hub.help('pytorch/vision', 'resnet18', force_reload=True))
torch.hub.list(github, force_reload=False) [source]
 
List all entrypoints available in github hubconf.  Parameters 
 
github (string) – a string with format “repo_owner/repo_name[:tag_name]” with an optional tag/branch. The default branch is master if not specified. Example: ‘pytorch/vision[:hub]’ 
force_reload (bool, optional) – whether to discard the existing cache and force a fresh download. Default is False.   Returns 
a list of available entrypoint names  Return type 
entrypoints   Example >>> entrypoints = torch.hub.list('pytorch/vision', force_reload=True)