neulab/docprompting-conala huggingface dataset:
torch.utils.checkpoint.checkpoint_sequential(functions, segments, input, **kwargs) [source]
 
A helper function for checkpointing sequential models. Sequential models execute a list of modules/functions in order (sequentially). Therefore, we can divide such a model in various segments and checkpoint each segment. All segments except the last will run in torch.no_grad() manner, i.e., not storing the intermediate activations. The inputs of each checkpointed segment will be saved for re-running the segment in the backward pass. See checkpoint() on how checkpointing works.  Warning Checkpointing doesn’t work with torch.autograd.grad(), but only with torch.autograd.backward().   Parameters 
 
functions – A torch.nn.Sequential or the list of modules or functions (comprising the model) to run sequentially. 
segments – Number of chunks to create in the model 
input – A Tensor that is input to functions
 
preserve_rng_state (bool, optional, default=True) – Omit stashing and restoring the RNG state during each checkpoint.   Returns 
Output of running functions sequentially on *inputs   Example >>> model = nn.Sequential(...)
>>> input_var = checkpoint_sequential(model, chunks, input_var)
torch.utils.cpp_extension.BuildExtension(*args, **kwargs) [source]
 
A custom setuptools build extension . This setuptools.build_ext subclass takes care of passing the minimum required compiler flags (e.g. -std=c++14) as well as mixed C++/CUDA compilation (and support for CUDA files in general). When using BuildExtension, it is allowed to supply a dictionary for extra_compile_args (rather than the usual list) that maps from languages (cxx or nvcc) to a list of additional compiler flags to supply to the compiler. This makes it possible to supply different flags to the C++ and CUDA compiler during mixed compilation. use_ninja (bool): If use_ninja is True (default), then we attempt to build using the Ninja backend. Ninja greatly speeds up compilation compared to the standard setuptools.build_ext. Fallbacks to the standard distutils backend if Ninja is not available.  Note By default, the Ninja backend uses #CPUS + 2 workers to build the extension. This may use up too many resources on some systems. One can control the number of workers by setting the MAX_JOBS environment variable to a non-negative number.
torch.utils.cpp_extension.check_compiler_abi_compatibility(compiler) [source]
 
Verifies that the given compiler is ABI-compatible with PyTorch.  Parameters 
compiler (str) – The compiler executable name to check (e.g. g++). Must be executable in a shell process.  Returns 
False if the compiler is (likely) ABI-incompatible with PyTorch, else True.
torch.utils.cpp_extension.CppExtension(name, sources, *args, **kwargs) [source]
 
Creates a setuptools.Extension for C++. Convenience method that creates a setuptools.Extension with the bare minimum (but often sufficient) arguments to build a C++ extension. All arguments are forwarded to the setuptools.Extension constructor. Example >>> from setuptools import setup
>>> from torch.utils.cpp_extension import BuildExtension, CppExtension
>>> setup(
        name='extension',
        ext_modules=[
            CppExtension(
                name='extension',
                sources=['extension.cpp'],
                extra_compile_args=['-g']),
        ],
        cmdclass={
            'build_ext': BuildExtension
        })
torch.utils.cpp_extension.CUDAExtension(name, sources, *args, **kwargs) [source]
 
Creates a setuptools.Extension for CUDA/C++. Convenience method that creates a setuptools.Extension with the bare minimum (but often sufficient) arguments to build a CUDA/C++ extension. This includes the CUDA include path, library path and runtime library. All arguments are forwarded to the setuptools.Extension constructor. Example >>> from setuptools import setup
>>> from torch.utils.cpp_extension import BuildExtension, CUDAExtension
>>> setup(
        name='cuda_extension',
        ext_modules=[
            CUDAExtension(
                    name='cuda_extension',
                    sources=['extension.cpp', 'extension_kernel.cu'],
                    extra_compile_args={'cxx': ['-g'],
                                        'nvcc': ['-O2']})
        ],
        cmdclass={
            'build_ext': BuildExtension
        })
 Compute capabilities: By default the extension will be compiled to run on all archs of the cards visible during the building process of the extension, plus PTX. If down the road a new card is installed the extension may need to be recompiled. If a visible card has a compute capability (CC) that’s newer than the newest version for which your nvcc can build fully-compiled binaries, Pytorch will make nvcc fall back to building kernels with the newest version of PTX your nvcc does support (see below for details on PTX). You can override the default behavior using TORCH_CUDA_ARCH_LIST to explicitly specify which CCs you want the extension to support: TORCH_CUDA_ARCH_LIST=”6.1 8.6” python build_my_extension.py TORCH_CUDA_ARCH_LIST=”5.2 6.0 6.1 7.0 7.5 8.0 8.6+PTX” python build_my_extension.py The +PTX option causes extension kernel binaries to include PTX instructions for the specified CC. PTX is an intermediate representation that allows kernels to runtime-compile for any CC >= the specified CC (for example, 8.6+PTX generates PTX that can runtime-compile for any GPU with CC >= 8.6). This improves your binary’s forward compatibility. However, relying on older PTX to provide forward compat by runtime-compiling for newer CCs can modestly reduce performance on those newer CCs. If you know exact CC(s) of the GPUs you want to target, you’re always better off specifying them individually. For example, if you want your extension to run on 8.0 and 8.6, “8.0+PTX” would work functionally because it includes PTX that can runtime-compile for 8.6, but “8.0 8.6” would be better. Note that while it’s possible to include all supported archs, the more archs get included the slower the building process will be, as it will build a separate kernel image for each arch.
torch.utils.cpp_extension.include_paths(cuda=False) [source]
 
Get the include paths required to build a C++ or CUDA extension.  Parameters 
cuda – If True, includes CUDA-specific include paths.  Returns 
A list of include path strings.
torch.utils.cpp_extension.is_ninja_available() [source]
 
Returns True if the ninja build system is available on the system, False otherwise.
torch.utils.cpp_extension.verify_ninja_availability() [source]
 
Raises RuntimeError if ninja build system is not available on the system, does nothing otherwise.
class torch.utils.data.BatchSampler(sampler, batch_size, drop_last) [source]
 
Wraps another sampler to yield a mini-batch of indices.  Parameters 
 
sampler (Sampler or Iterable) – Base sampler. Can be any iterable object 
batch_size (int) – Size of mini-batch. 
drop_last (bool) – If True, the sampler will drop the last batch if its size would be less than batch_size
    Example >>> list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=False))
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
>>> list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=True))
[[0, 1, 2], [3, 4, 5], [6, 7, 8]]
class torch.utils.data.BufferedShuffleDataset(dataset, buffer_size) [source]
 
Dataset shuffled from the original dataset. This class is useful to shuffle an existing instance of an IterableDataset. The buffer with buffer_size is filled with the items from the dataset first. Then, each item will be yielded from the buffer by reservoir sampling via iterator. buffer_size is required to be larger than 0. For buffer_size == 1, the dataset is not shuffled. In order to fully shuffle the whole dataset, buffer_size is required to be greater than or equal to the size of dataset. When it is used with DataLoader, each item in the dataset will be yielded from the DataLoader iterator. And, the method to set up a random seed is different based on num_workers. For single-process mode (num_workers == 0), the random seed is required to be set before the DataLoader in the main process. >>> ds = BufferedShuffleDataset(dataset)
>>> random.seed(...)
>>> print(list(torch.utils.data.DataLoader(ds, num_workers=0)))
 For multi-process mode (num_workers > 0), the random seed is set by a callable function in each worker. >>> ds = BufferedShuffleDataset(dataset)
>>> def init_fn(worker_id):
...     random.seed(...)
>>> print(list(torch.utils.data.DataLoader(ds, ..., num_workers=n, worker_init_fn=init_fn)))
  Parameters 
 
dataset (IterableDataset) – The original IterableDataset. 
buffer_size (int) – The buffer size for shuffling.
class torch.utils.data.ChainDataset(datasets) [source]
 
Dataset for chainning multiple IterableDataset s. This class is useful to assemble different existing dataset streams. The chainning operation is done on-the-fly, so concatenating large-scale datasets with this class will be efficient.  Parameters 
datasets (iterable of IterableDataset) – datasets to be chained together
class torch.utils.data.ConcatDataset(datasets) [source]
 
Dataset as a concatenation of multiple datasets. This class is useful to assemble different existing datasets.  Parameters 
datasets (sequence) – List of datasets to be concatenated
class torch.utils.data.Dataset [source]
 
An abstract class representing a Dataset. All datasets that represent a map from keys to data samples should subclass it. All subclasses should overwrite __getitem__(), supporting fetching a data sample for a given key. Subclasses could also optionally overwrite __len__(), which is expected to return the size of the dataset by many Sampler implementations and the default options of DataLoader.  Note DataLoader by default constructs a index sampler that yields integral indices. To make it work with a map-style dataset with non-integral indices/keys, a custom sampler must be provided.
class torch.utils.data.distributed.DistributedSampler(dataset, num_replicas=None, rank=None, shuffle=True, seed=0, drop_last=False) [source]
 
Sampler that restricts data loading to a subset of the dataset. It is especially useful in conjunction with torch.nn.parallel.DistributedDataParallel. In such a case, each process can pass a DistributedSampler instance as a DataLoader sampler, and load a subset of the original dataset that is exclusive to it.  Note Dataset is assumed to be of constant size.   Parameters 
 
dataset – Dataset used for sampling. 
num_replicas (int, optional) – Number of processes participating in distributed training. By default, world_size is retrieved from the current distributed group. 
rank (int, optional) – Rank of the current process within num_replicas. By default, rank is retrieved from the current distributed group. 
shuffle (bool, optional) – If True (default), sampler will shuffle the indices. 
seed (int, optional) – random seed used to shuffle the sampler if shuffle=True. This number should be identical across all processes in the distributed group. Default: 0. 
drop_last (bool, optional) – if True, then the sampler will drop the tail of the data to make it evenly divisible across the number of replicas. If False, the sampler will add extra indices to make the data evenly divisible across the replicas. Default: False.     Warning In distributed mode, calling the set_epoch() method at the beginning of each epoch before creating the DataLoader iterator is necessary to make shuffling work properly across multiple epochs. Otherwise, the same ordering will be always used.  Example: >>> sampler = DistributedSampler(dataset) if is_distributed else None
>>> loader = DataLoader(dataset, shuffle=(sampler is None),
...                     sampler=sampler)
>>> for epoch in range(start_epoch, n_epochs):
...     if is_distributed:
...         sampler.set_epoch(epoch)
...     train(loader)
torch.utils.data.get_worker_info() [source]
 
Returns the information about the current DataLoader iterator worker process. When called in a worker, this returns an object guaranteed to have the following attributes:  
id: the current worker id. 
num_workers: the total number of workers. 
seed: the random seed set for the current worker. This value is determined by main process RNG and the worker id. See DataLoader’s documentation for more details. 
dataset: the copy of the dataset object in this process. Note that this will be a different object in a different process than the one in the main process.  When called in the main process, this returns None.  Note When used in a worker_init_fn passed over to DataLoader, this method can be useful to set up each worker process differently, for instance, using worker_id to configure the dataset object to only read a specific fraction of a sharded dataset, or use seed to seed other libraries used in dataset code (e.g., NumPy).
class torch.utils.data.RandomSampler(data_source, replacement=False, num_samples=None, generator=None) [source]
 
Samples elements randomly. If without replacement, then sample from a shuffled dataset. If with replacement, then user can specify num_samples to draw.  Parameters 
 
data_source (Dataset) – dataset to sample from 
replacement (bool) – samples are drawn on-demand with replacement if True, default=``False`` 
num_samples (int) – number of samples to draw, default=`len(dataset)`. This argument is supposed to be specified only when replacement is True. 
generator (Generator) – Generator used in sampling.
torch.utils.data.random_split(dataset, lengths, generator=<torch._C.Generator object>) [source]
 
Randomly split a dataset into non-overlapping new datasets of given lengths. Optionally fix the generator for reproducible results, e.g.: >>> random_split(range(10), [3, 7], generator=torch.Generator().manual_seed(42))
  Parameters 
 
dataset (Dataset) – Dataset to be split 
lengths (sequence) – lengths of splits to be produced 
generator (Generator) – Generator used for the random permutation.
class torch.utils.data.Sampler(data_source) [source]
 
Base class for all Samplers. Every Sampler subclass has to provide an __iter__() method, providing a way to iterate over indices of dataset elements, and a __len__() method that returns the length of the returned iterators.  Note The __len__() method isn’t strictly required by DataLoader, but is expected in any calculation involving the length of a DataLoader.
class torch.utils.data.SequentialSampler(data_source) [source]
 
Samples elements sequentially, always in the same order.  Parameters 
data_source (Dataset) – dataset to sample from
class torch.utils.data.Subset(dataset, indices) [source]
 
Subset of a dataset at specified indices.  Parameters 
 
dataset (Dataset) – The whole Dataset 
indices (sequence) – Indices in the whole set selected for subset
class torch.utils.data.SubsetRandomSampler(indices, generator=None) [source]
 
Samples elements randomly from a given list of indices, without replacement.  Parameters 
 
indices (sequence) – a sequence of indices 
generator (Generator) – Generator used in sampling.
class torch.utils.data.TensorDataset(*tensors) [source]
 
Dataset wrapping tensors. Each sample will be retrieved by indexing tensors along the first dimension.  Parameters 
*tensors (Tensor) – tensors that have the same size of the first dimension.
class torch.utils.data.WeightedRandomSampler(weights, num_samples, replacement=True, generator=None) [source]
 
Samples elements from [0,..,len(weights)-1] with given probabilities (weights).  Parameters 
 
weights (sequence) – a sequence of weights, not necessary summing up to one 
num_samples (int) – number of samples to draw 
replacement (bool) – if True, samples are drawn with replacement. If not, they are drawn without replacement, which means that when a sample index is drawn for a row, it cannot be drawn again for that row. 
generator (Generator) – Generator used in sampling.    Example >>> list(WeightedRandomSampler([0.1, 0.9, 0.4, 0.7, 3.0, 0.6], 5, replacement=True))
[4, 4, 1, 4, 5]
>>> list(WeightedRandomSampler([0.9, 0.4, 0.05, 0.2, 0.3, 0.1], 5, replacement=False))
[0, 1, 4, 3, 2]
torch.utils.dlpack  
torch.utils.dlpack.from_dlpack(dlpack) → Tensor  
Decodes a DLPack to a tensor.  Parameters 
dlpack – a PyCapsule object with the dltensor   The tensor will share the memory with the object represented in the dlpack. Note that each dlpack can only be consumed once. 
  
torch.utils.dlpack.to_dlpack(tensor) → PyCapsule  
Returns a DLPack representing the tensor.  Parameters 
tensor – a tensor to be exported   The dlpack shares the tensors memory. Note that each dlpack can only be consumed once.
torch.utils.dlpack.from_dlpack(dlpack) → Tensor  
Decodes a DLPack to a tensor.  Parameters 
dlpack – a PyCapsule object with the dltensor   The tensor will share the memory with the object represented in the dlpack. Note that each dlpack can only be consumed once.
torch.utils.dlpack.to_dlpack(tensor) → PyCapsule  
Returns a DLPack representing the tensor.  Parameters 
tensor – a tensor to be exported   The dlpack shares the tensors memory. Note that each dlpack can only be consumed once.
torch.utils.mobile_optimizer.optimize_for_mobile(script_module, optimization_blocklist=None, preserved_methods=None, backend='CPU') [source]
 
 Parameters 
 
script_module – An instance of torch script module with type of ScriptModule. 
optimization_blocklist – A set with type of MobileOptimizerType. When set is not passed, optimization method will run all the optimizer pass; otherwise, optimizer method will run the optimization pass that is not included inside optimization_blocklist. 
perserved_methods – A list of methods that needed to be preserved when freeze_module pass is invoked 
backend – Device type to use for running the result model (‘CPU’(default), ‘Vulkan’ or ‘Metal’).   Returns 
A new optimized torch script module
torch.utils.model_zoo Moved to torch.hub.  
torch.utils.model_zoo.load_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None)  
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.utils.model_zoo.load_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None)  
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')
add_audio(tag, snd_tensor, global_step=None, sample_rate=44100, walltime=None) [source]
 
Add audio data to summary.  Parameters 
 
tag (string) – Data identifier 
snd_tensor (torch.Tensor) – Sound data 
global_step (int) – Global step value to record 
sample_rate (int) – sample rate in Hz 
walltime (float) – Optional override default walltime (time.time()) seconds after epoch of event     Shape:

snd_tensor: (1,L)(1, L) . The values should lie between [-1, 1].
add_custom_scalars(layout) [source]
 
Create special chart by collecting charts tags in ‘scalars’. Note that this function can only be called once for each SummaryWriter() object. Because it only provides metadata to tensorboard, the function can be called before or after the training loop.  Parameters 
layout (dict) – {categoryName: charts}, where charts is also a dictionary {chartName: ListOfProperties}. The first element in ListOfProperties is the chart’s type (one of Multiline or Margin) and the second element should be a list containing the tags you have used in add_scalar function, which will be collected into the new chart.   Examples: layout = {'Taiwan':{'twse':['Multiline',['twse/0050', 'twse/2330']]},
             'USA':{ 'dow':['Margin',   ['dow/aaa', 'dow/bbb', 'dow/ccc']],
                  'nasdaq':['Margin',   ['nasdaq/aaa', 'nasdaq/bbb', 'nasdaq/ccc']]}}

writer.add_custom_scalars(layout)
add_embedding(mat, metadata=None, label_img=None, global_step=None, tag='default', metadata_header=None) [source]
 
Add embedding projector data to summary.  Parameters 
 
mat (torch.Tensor or numpy.array) – A matrix which each row is the feature vector of the data point 
metadata (list) – A list of labels, each element will be convert to string 
label_img (torch.Tensor) – Images correspond to each data point 
global_step (int) – Global step value to record 
tag (string) – Name for the embedding     Shape:

mat: (N,D)(N, D) , where N is number of data and D is feature dimension label_img: (N,C,H,W)(N, C, H, W)    Examples: import keyword
import torch
meta = []
while len(meta)<100:
    meta = meta+keyword.kwlist # get some strings
meta = meta[:100]

for i, v in enumerate(meta):
    meta[i] = v+str(i)

label_img = torch.rand(100, 3, 10, 32)
for i in range(100):
    label_img[i]*=i/100.0

writer.add_embedding(torch.randn(100, 5), metadata=meta, label_img=label_img)
writer.add_embedding(torch.randn(100, 5), label_img=label_img)
writer.add_embedding(torch.randn(100, 5), metadata=meta)
add_figure(tag, figure, global_step=None, close=True, walltime=None) [source]
 
Render matplotlib figure into an image and add it to summary. Note that this requires the matplotlib package.  Parameters 
 
tag (string) – Data identifier 
figure (matplotlib.pyplot.figure) – Figure or a list of figures 
global_step (int) – Global step value to record 
close (bool) – Flag to automatically close the figure 
walltime (float) – Optional override default walltime (time.time()) seconds after epoch of event
add_graph(model, input_to_model=None, verbose=False) [source]
 
Add graph data to summary.  Parameters 
 
model (torch.nn.Module) – Model to draw. 
input_to_model (torch.Tensor or list of torch.Tensor) – A variable or a tuple of variables to be fed. 
verbose (bool) – Whether to print graph structure in console.