neulab/docprompting-conala huggingface dataset:
parameters(recurse=True) [source]
 
Returns an iterator over module parameters. This is typically passed to an optimizer.  Parameters 
recurse (bool) – if True, then yields parameters of this module and all submodules. Otherwise, yields only parameters that are direct members of this module.  Yields 
Parameter – module parameter   Example: >>> for param in model.parameters():
>>>     print(type(param), param.size())
<class 'torch.Tensor'> (20L,)
<class 'torch.Tensor'> (20L, 1L, 5L, 5L)
register_backward_hook(hook) [source]
 
Registers a backward hook on the module. This function is deprecated in favor of nn.Module.register_full_backward_hook() and the behavior of this function will change in future versions.  Returns 
a handle that can be used to remove the added hook by calling handle.remove()  Return type 
torch.utils.hooks.RemovableHandle
register_buffer(name, tensor, persistent=True) [source]
 
Adds a buffer to the module. This is typically used to register a buffer that should not to be considered a model parameter. For example, BatchNorm’s running_mean is not a parameter, but is part of the module’s state. Buffers, by default, are persistent and will be saved alongside parameters. This behavior can be changed by setting persistent to False. The only difference between a persistent buffer and a non-persistent buffer is that the latter will not be a part of this module’s state_dict. Buffers can be accessed as attributes using given names.  Parameters 
 
name (string) – name of the buffer. The buffer can be accessed from this module using the given name 
tensor (Tensor) – buffer to be registered. 
persistent (bool) – whether the buffer is part of this module’s state_dict.    Example: >>> self.register_buffer('running_mean', torch.zeros(num_features))
register_forward_hook(hook) [source]
 
Registers a forward hook on the module. The hook will be called every time after forward() has computed an output. It should have the following signature: hook(module, input, output) -> None or modified output
 The input contains only the positional arguments given to the module. Keyword arguments won’t be passed to the hooks and only to the forward. The hook can modify the output. It can modify the input inplace but it will not have effect on forward since this is called after forward() is called.  Returns 
a handle that can be used to remove the added hook by calling handle.remove()  Return type 
torch.utils.hooks.RemovableHandle
register_forward_pre_hook(hook) [source]
 
Registers a forward pre-hook on the module. The hook will be called every time before forward() is invoked. It should have the following signature: hook(module, input) -> None or modified input
 The input contains only the positional arguments given to the module. Keyword arguments won’t be passed to the hooks and only to the forward. The hook can modify the input. User can either return a tuple or a single modified value in the hook. We will wrap the value into a tuple if a single value is returned(unless that value is already a tuple).  Returns 
a handle that can be used to remove the added hook by calling handle.remove()  Return type 
torch.utils.hooks.RemovableHandle
register_full_backward_hook(hook) [source]
 
Registers a backward hook on the module. The hook will be called every time the gradients with respect to module inputs are computed. The hook should have the following signature: hook(module, grad_input, grad_output) -> tuple(Tensor) or None
 The grad_input and grad_output are tuples that contain the gradients with respect to the inputs and outputs respectively. The hook should not modify its arguments, but it can optionally return a new gradient with respect to the input that will be used in place of grad_input in subsequent computations. grad_input will only correspond to the inputs given as positional arguments and all kwarg arguments are ignored. Entries in grad_input and grad_output will be None for all non-Tensor arguments.  Warning Modifying inputs or outputs inplace is not allowed when using backward hooks and will raise an error.   Returns 
a handle that can be used to remove the added hook by calling handle.remove()  Return type 
torch.utils.hooks.RemovableHandle
register_parameter(name, param) [source]
 
Adds a parameter to the module. The parameter can be accessed as an attribute using given name.  Parameters 
 
name (string) – name of the parameter. The parameter can be accessed from this module using the given name 
param (Parameter) – parameter to be added to the module.
requires_grad_(requires_grad=True) [source]
 
Change if autograd should record operations on parameters in this module. This method sets the parameters’ requires_grad attributes in-place. This method is helpful for freezing part of the module for finetuning or training parts of a model individually (e.g., GAN training).  Parameters 
requires_grad (bool) – whether autograd should record operations on parameters in this module. Default: True.  Returns 
self  Return type 
Module
state_dict(destination=None, prefix='', keep_vars=False) [source]
 
Returns a dictionary containing a whole state of the module. Both parameters and persistent buffers (e.g. running averages) are included. Keys are corresponding parameter and buffer names.  Returns 
a dictionary containing a whole state of the module  Return type 
dict   Example: >>> module.state_dict().keys()
['bias', 'weight']
to(*args, **kwargs) [source]
 
Moves and/or casts the parameters and buffers. This can be called as  
to(device=None, dtype=None, non_blocking=False) [source]

  
to(dtype, non_blocking=False) [source]

  
to(tensor, non_blocking=False) [source]

  
to(memory_format=torch.channels_last) [source]

 Its signature is similar to torch.Tensor.to(), but only accepts floating point or complex dtype`s. In addition, this method will
only cast the floating point or complex parameters and buffers to :attr:`dtype (if given). The integral parameters and buffers will be moved device, if that is given, but with dtypes unchanged. When non_blocking is set, it tries to convert/move asynchronously with respect to the host if possible, e.g., moving CPU Tensors with pinned memory to CUDA devices. See below for examples.  Note This method modifies the module in-place.   Parameters 
 
device (torch.device) – the desired device of the parameters and buffers in this module 
dtype (torch.dtype) – the desired floating point or complex dtype of the parameters and buffers in this module 
tensor (torch.Tensor) – Tensor whose dtype and device are the desired dtype and device for all parameters and buffers in this module 
memory_format (torch.memory_format) – the desired memory format for 4D parameters and buffers in this module (keyword only argument)   Returns 
self  Return type 
Module   Examples: >>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]])
>>> linear.to(torch.double)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]], dtype=torch.float64)
>>> gpu1 = torch.device("cuda:1")
>>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
>>> cpu = torch.device("cpu")
>>> linear.to(cpu)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16)

>>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
>>> linear.weight
Parameter containing:
tensor([[ 0.3741+0.j,  0.2382+0.j],
        [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
>>> linear(torch.ones(3, 2, dtype=torch.cdouble))
tensor([[0.6122+0.j, 0.1150+0.j],
        [0.6122+0.j, 0.1150+0.j],
        [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
train(mode=True) [source]
 
Sets the module in training mode. This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation mode, if they are affected, e.g. Dropout, BatchNorm, etc.  Parameters 
mode (bool) – whether to set training mode (True) or evaluation mode (False). Default: True.  Returns 
self  Return type 
Module
type(dst_type) [source]
 
Casts all parameters and buffers to dst_type.  Parameters 
dst_type (type or string) – the desired type  Returns 
self  Return type 
Module
xpu(device=None) [source]
 
Moves all model parameters and buffers to the XPU. This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on XPU while being optimized.  Parameters 
device (int, optional) – if specified, all parameters will be copied to that device  Returns 
self  Return type 
Module
zero_grad(set_to_none=False) [source]
 
Sets gradients of all model parameters to zero. See similar function under torch.optim.Optimizer for more context.  Parameters 
set_to_none (bool) – instead of setting to zero, set the grads to None. See torch.optim.Optimizer.zero_grad() for details.
class torch.nn.ModuleDict(modules=None) [source]
 
Holds submodules in a dictionary. ModuleDict can be indexed like a regular Python dictionary, but modules it contains are properly registered, and will be visible by all Module methods. ModuleDict is an ordered dictionary that respects  the order of insertion, and in update(), the order of the merged OrderedDict, dict (started from Python 3.6) or another ModuleDict (the argument to update()).  Note that update() with other unordered mapping types (e.g., Python’s plain dict before Python version 3.6) does not preserve the order of the merged mapping.  Parameters 
modules (iterable, optional) – a mapping (dictionary) of (string: module) or an iterable of key-value pairs of type (string, module)   Example: class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.choices = nn.ModuleDict({
                'conv': nn.Conv2d(10, 10, 3),
                'pool': nn.MaxPool2d(3)
        })
        self.activations = nn.ModuleDict([
                ['lrelu', nn.LeakyReLU()],
                ['prelu', nn.PReLU()]
        ])

    def forward(self, x, choice, act):
        x = self.choices[choice](x)
        x = self.activations[act](x)
        return x
  
clear() [source]
 
Remove all items from the ModuleDict. 
  
items() [source]
 
Return an iterable of the ModuleDict key/value pairs. 
  
keys() [source]
 
Return an iterable of the ModuleDict keys. 
  
pop(key) [source]
 
Remove key from the ModuleDict and return its module.  Parameters 
key (string) – key to pop from the ModuleDict   
  
update(modules) [source]
 
Update the ModuleDict with the key-value pairs from a mapping or an iterable, overwriting existing keys.  Note If modules is an OrderedDict, a ModuleDict, or an iterable of key-value pairs, the order of new elements in it is preserved.   Parameters 
modules (iterable) – a mapping (dictionary) from string to Module, or an iterable of key-value pairs of type (string, Module)   
  
values() [source]
 
Return an iterable of the ModuleDict values.
items() [source]
 
Return an iterable of the ModuleDict key/value pairs.
pop(key) [source]
 
Remove key from the ModuleDict and return its module.  Parameters 
key (string) – key to pop from the ModuleDict
update(modules) [source]
 
Update the ModuleDict with the key-value pairs from a mapping or an iterable, overwriting existing keys.  Note If modules is an OrderedDict, a ModuleDict, or an iterable of key-value pairs, the order of new elements in it is preserved.   Parameters 
modules (iterable) – a mapping (dictionary) from string to Module, or an iterable of key-value pairs of type (string, Module)
class torch.nn.ModuleList(modules=None) [source]
 
Holds submodules in a list. ModuleList can be indexed like a regular Python list, but modules it contains are properly registered, and will be visible by all Module methods.  Parameters 
modules (iterable, optional) – an iterable of modules to add   Example: class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.linears = nn.ModuleList([nn.Linear(10, 10) for i in range(10)])

    def forward(self, x):
        # ModuleList can act as an iterable, or be indexed using ints
        for i, l in enumerate(self.linears):
            x = self.linears[i // 2](x) + l(x)
        return x
  
append(module) [source]
 
Appends a given module to the end of the list.  Parameters 
module (nn.Module) – module to append   
  
extend(modules) [source]
 
Appends modules from a Python iterable to the end of the list.  Parameters 
modules (iterable) – iterable of modules to append   
  
insert(index, module) [source]
 
Insert a given module before a given index in the list.  Parameters 
 
index (int) – index to insert. 
module (nn.Module) – module to insert
append(module) [source]
 
Appends a given module to the end of the list.  Parameters 
module (nn.Module) – module to append
extend(modules) [source]
 
Appends modules from a Python iterable to the end of the list.  Parameters 
modules (iterable) – iterable of modules to append
insert(index, module) [source]
 
Insert a given module before a given index in the list.  Parameters 
 
index (int) – index to insert. 
module (nn.Module) – module to insert
has_uninitialized_params() [source]
 
Check if a module has parameters that are not initialized
initialize_parameters(*args, **kwargs) [source]
 
Initialize parameters according to the input batch properties. This adds an interface to isolate parameter initialization from the forward pass when doing parameter shape inference.
torch.nn.modules.module.register_module_backward_hook(hook) [source]
 
Registers a backward hook common to all the modules. This function is deprecated in favor of nn.module.register_module_full_backward_hook() and the behavior of this function will change in future versions.  Returns 
a handle that can be used to remove the added hook by calling handle.remove()  Return type 
torch.utils.hooks.RemovableHandle
torch.nn.modules.module.register_module_forward_hook(hook) [source]
 
Registers a global forward hook for all the modules  Warning This adds global state to the nn.module module and it is only intended for debugging/profiling purposes.  The hook will be called every time after forward() has computed an output. It should have the following signature: hook(module, input, output) -> None or modified output
 The input contains only the positional arguments given to the module. Keyword arguments won’t be passed to the hooks and only to the forward. The hook can modify the output. It can modify the input inplace but it will not have effect on forward since this is called after forward() is called.  Returns 
a handle that can be used to remove the added hook by calling handle.remove()  Return type 
torch.utils.hooks.RemovableHandle   This hook will be executed before specific module hooks registered with register_forward_hook.
torch.nn.modules.module.register_module_forward_pre_hook(hook) [source]
 
Registers a forward pre-hook common to all modules.  Warning This adds global state to the nn.module module and it is only intended for debugging/profiling purposes.  The hook will be called every time before forward() is invoked. It should have the following signature: hook(module, input) -> None or modified input
 The input contains only the positional arguments given to the module. Keyword arguments won’t be passed to the hooks and only to the forward. The hook can modify the input. User can either return a tuple or a single modified value in the hook. We will wrap the value into a tuple if a single value is returned(unless that value is already a tuple). This hook has precedence over the specific module hooks registered with register_forward_pre_hook.  Returns 
a handle that can be used to remove the added hook by calling handle.remove()  Return type 
torch.utils.hooks.RemovableHandle
class torch.nn.MSELoss(size_average=None, reduce=None, reduction='mean') [source]
 
Creates a criterion that measures the mean squared error (squared L2 norm) between each element in the input xx  and target yy . The unreduced (i.e. with reduction set to 'none') loss can be described as:  ℓ(x,y)=L={l1,…,lN}⊤,ln=(xn−yn)2,\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad l_n = \left( x_n - y_n \right)^2,  
where NN  is the batch size. If reduction is not 'none' (default 'mean'), then:  ℓ(x,y)={mean⁡(L),if reduction=‘mean’;sum⁡(L),if reduction=‘sum’.\ell(x, y) = \begin{cases} \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} \end{cases}  
xx  and yy  are tensors of arbitrary shapes with a total of nn  elements each. The mean operation still operates over all the elements, and divides by nn . The division by nn  can be avoided if one sets reduction = 'sum'.  Parameters 
 
size_average (bool, optional) – Deprecated (see reduction). By default, the losses are averaged over each loss element in the batch. Note that for some losses, there are multiple elements per sample. If the field size_average is set to False, the losses are instead summed for each minibatch. Ignored when reduce is False. Default: True
 
reduce (bool, optional) – Deprecated (see reduction). By default, the losses are averaged or summed over observations for each minibatch depending on size_average. When reduce is False, returns a loss per batch element instead and ignores size_average. Default: True
 
reduction (string, optional) – Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied, 'mean': the sum of the output will be divided by the number of elements in the output, 'sum': the output will be summed. Note: size_average and reduce are in the process of being deprecated, and in the meantime, specifying either of those two args will override reduction. Default: 'mean'
     Shape:

 Input: (N,∗)(N, *)  where ∗*  means, any number of additional dimensions Target: (N,∗)(N, *) , same shape as the input    Examples: >>> loss = nn.MSELoss()
>>> input = torch.randn(3, 5, requires_grad=True)
>>> target = torch.randn(3, 5)
>>> output = loss(input, target)
>>> output.backward()
forward(query, key, value, key_padding_mask=None, need_weights=True, attn_mask=None) [source]
 
 Parameters 
 
key, value (query,) – map a query and a set of key-value pairs to an output. See “Attention Is All You Need” for more details. 
key_padding_mask – if provided, specified padding elements in the key will be ignored by the attention. When given a binary mask and a value is True, the corresponding value on the attention layer will be ignored. When given a byte mask and a value is non-zero, the corresponding value on the attention layer will be ignored 
need_weights – output attn_output_weights. 
attn_mask – 2D or 3D mask that prevents attention to certain positions. A 2D mask will be broadcasted for all the batches while a 3D mask allows to specify a different mask for the entries of each batch.     Shapes for inputs:

 query: (L,N,E)(L, N, E)  where L is the target sequence length, N is the batch size, E is the embedding dimension. key: (S,N,E)(S, N, E) , where S is the source sequence length, N is the batch size, E is the embedding dimension. value: (S,N,E)(S, N, E)  where S is the source sequence length, N is the batch size, E is the embedding dimension. key_padding_mask: (N,S)(N, S)  where N is the batch size, S is the source sequence length. If a ByteTensor is provided, the non-zero positions will be ignored while the position with the zero positions will be unchanged. If a BoolTensor is provided, the positions with the value of True will be ignored while the position with the value of False will be unchanged. 
attn_mask: if a 2D mask: (L,S)(L, S)  where L is the target sequence length, S is the source sequence length. If a 3D mask: (N⋅num_heads,L,S)(N\cdot\text{num\_heads}, L, S)  where N is the batch size, L is the target sequence length, S is the source sequence length. attn_mask ensure that position i is allowed to attend the unmasked positions. If a ByteTensor is provided, the non-zero positions are not allowed to attend while the zero positions will be unchanged. If a BoolTensor is provided, positions with True is not allowed to attend while False values will be unchanged. If a FloatTensor is provided, it will be added to the attention weight.    Shapes for outputs:

 attn_output: (L,N,E)(L, N, E)  where L is the target sequence length, N is the batch size, E is the embedding dimension. attn_output_weights: (N,L,S)(N, L, S)  where N is the batch size, L is the target sequence length, S is the source sequence length.
class torch.nn.MultiLabelMarginLoss(size_average=None, reduce=None, reduction='mean') [source]
 
Creates a criterion that optimizes a multi-class multi-classification hinge loss (margin-based loss) between input xx  (a 2D mini-batch Tensor) and output yy  (which is a 2D Tensor of target class indices). For each sample in the mini-batch:  loss(x,y)=∑ijmax⁡(0,1−(x[y[j]]−x[i]))x.size(0)\text{loss}(x, y) = \sum_{ij}\frac{\max(0, 1 - (x[y[j]] - x[i]))}{\text{x.size}(0)}  
where x∈{0,⋯,x.size(0)−1}x \in \left\{0, \; \cdots , \; \text{x.size}(0) - 1\right\} , y∈{0,⋯,y.size(0)−1}y \in \left\{0, \; \cdots , \; \text{y.size}(0) - 1\right\} , 0≤y[j]≤x.size(0)−10 \leq y[j] \leq \text{x.size}(0)-1 , and i≠y[j]i \neq y[j]  for all ii  and jj . yy  and xx  must have the same size. The criterion only considers a contiguous block of non-negative targets that starts at the front. This allows for different samples to have variable amounts of target classes.  Parameters 
 
size_average (bool, optional) – Deprecated (see reduction). By default, the losses are averaged over each loss element in the batch. Note that for some losses, there are multiple elements per sample. If the field size_average is set to False, the losses are instead summed for each minibatch. Ignored when reduce is False. Default: True
 
reduce (bool, optional) – Deprecated (see reduction). By default, the losses are averaged or summed over observations for each minibatch depending on size_average. When reduce is False, returns a loss per batch element instead and ignores size_average. Default: True
 
reduction (string, optional) – Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied, 'mean': the sum of the output will be divided by the number of elements in the output, 'sum': the output will be summed. Note: size_average and reduce are in the process of being deprecated, and in the meantime, specifying either of those two args will override reduction. Default: 'mean'
     Shape:

 Input: (C)(C)  or (N,C)(N, C)  where N is the batch size and C is the number of classes. Target: (C)(C)  or (N,C)(N, C) , label targets padded by -1 ensuring same shape as the input. Output: scalar. If reduction is 'none', then (N)(N) .    Examples: >>> loss = nn.MultiLabelMarginLoss()
>>> x = torch.FloatTensor([[0.1, 0.2, 0.4, 0.8]])
>>> # for target y, only consider labels 3 and 0, not after label -1
>>> y = torch.LongTensor([[3, 0, -1, 1]])
>>> loss(x, y)
>>> # 0.25 * ((1-(0.1-0.2)) + (1-(0.1-0.4)) + (1-(0.8-0.2)) + (1-(0.8-0.4)))
tensor(0.8500)