id int64 0 190k | prompt stringlengths 21 13.4M | docstring stringlengths 1 12k ⌀ |
|---|---|---|
21,300 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
def _i... | null |
21,301 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
def _i... | null |
21,302 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
def _i... | null |
21,303 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet 18 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,304 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet V2 18 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,305 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet 34 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,306 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet V2 34 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,307 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet 50 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,308 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet V2 50 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,309 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | ResNet 50 implementation where channel sizes for 3x3 convolutions are doubled; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,310 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNext 50 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,311 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet 101 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,312 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet V2 101 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,313 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | ResNet 101 implementation where channel sizes for 3x3 convolutions are doubled; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,314 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNext 101 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,315 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet 152 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,316 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNet V2 152 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,317 | from typing import List
from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class R... | Standard ResNext 152 implementation; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created ResNet Module |
21,318 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
def _init_conv(c... | null |
21,319 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
def _init_batch_... | null |
21,320 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
def _init_linear... | null |
21,321 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | Standard VGG 11; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,322 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | VGG 11 with batch norm added; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,323 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | Standard VGG 13; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,324 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | VGG 13 with batch norm added; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,325 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | Standard VGG 16; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,326 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | VGG 16 with batch norm added; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,327 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | Standard VGG 19; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,328 | from typing import List
from torch import Tensor
from torch.nn import (
BatchNorm2d,
Conv2d,
Dropout,
Linear,
MaxPool2d,
Module,
Sequential,
Sigmoid,
Softmax,
init,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class VGGSectionS... | VGG 19 with batch norm added; expected input shape is (B, 3, 224, 224) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MobileNet Module |
21,329 | from torch import Tensor
from torch.nn import (
AdaptiveAvgPool2d,
BatchNorm2d,
Conv2d,
Linear,
Module,
Sequential,
Sigmoid,
Softmax,
)
from sparseml.pytorch.models.registry import ModelRegistry
from sparseml.pytorch.nn import ReLU
class MnistNet(Module):
"""
A simple convolution... | MnistNet implementation; expected input shape is (B, 1, 28, 28) :param num_classes: the number of classes to classify :param class_type: one of [single, multi] to support multi class training; default single :return: The created MnistNet Module |
21,330 | import collections
import json
import logging
import os
import shutil
import warnings
from copy import deepcopy
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
import numpy
import onnx
import torch
from onnx import numpy_helper
from packaging import version
from torch import Tensor
from t... | Export an onnx file for the current module and for a sample batch. Sample batch used to feed through the model to freeze the graph for a particular execution. :param module: torch Module object to export :param sample_batch: the batch to export an onnx for, handles creating the static graph for onnx as well as setting ... |
21,331 | import collections
import json
import logging
import os
import shutil
import warnings
from copy import deepcopy
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
import numpy
import onnx
import torch
from onnx import numpy_helper
from packaging import version
from torch import Tensor
from t... | null |
21,332 | import collections
import json
import logging
import os
import shutil
import warnings
from copy import deepcopy
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
import numpy
import onnx
import torch
from onnx import numpy_helper
from packaging import version
from torch import Tensor
from t... | null |
21,333 | import collections
import json
import logging
import os
import shutil
import warnings
from copy import deepcopy
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
import numpy
import onnx
import torch
from onnx import numpy_helper
from packaging import version
from torch import Tensor
from t... | Appends `labels_to_class_mapping` information to the config.json file: - new key: `labels_to_class_mapping` - new value: a dictionary that maps the integer labels to string class names If config.json already contains `labels_to_class_mapping`, this information will be overwritten :param labels_to_class_mapping: informa... |
21,334 | from typing import Any, Dict, Iterable
import numpy
from torch import Tensor
from sparseml.utils.datasets import (
CIFAR_10_CLASSES,
COCO_CLASSES,
COCO_CLASSES_80,
IMAGENET_CLASSES,
IMAGENETTE_CLASSES,
VOC_CLASSES,
)
def apply_one_hot_label_mapping(labels: Tensor, class_names: Dict[Any, str]):
... | null |
21,335 | from typing import Any, Dict, Iterable
import numpy
from torch import Tensor
from sparseml.utils.datasets import (
CIFAR_10_CLASSES,
COCO_CLASSES,
COCO_CLASSES_80,
IMAGENET_CLASSES,
IMAGENETTE_CLASSES,
VOC_CLASSES,
)
def apply_one_hot_label_mapping(labels: Tensor, class_names: Dict[Any, str]):
... | null |
21,336 | from typing import Any, Dict, Iterable
import numpy
from torch import Tensor
from sparseml.utils.datasets import (
CIFAR_10_CLASSES,
COCO_CLASSES,
COCO_CLASSES_80,
IMAGENET_CLASSES,
IMAGENETTE_CLASSES,
VOC_CLASSES,
)
def apply_one_hot_label_mapping(labels: Tensor, class_names: Dict[Any, str]):
... | null |
21,337 | from typing import Any, Dict, Iterable
import numpy
from torch import Tensor
from sparseml.utils.datasets import (
CIFAR_10_CLASSES,
COCO_CLASSES,
COCO_CLASSES_80,
IMAGENET_CLASSES,
IMAGENETTE_CLASSES,
VOC_CLASSES,
)
def apply_one_hot_label_mapping(labels: Tensor, class_names: Dict[Any, str]):
... | null |
21,338 | from typing import Any, Dict, Iterable
import numpy
from torch import Tensor
from sparseml.utils.datasets import (
CIFAR_10_CLASSES,
COCO_CLASSES,
COCO_CLASSES_80,
IMAGENET_CLASSES,
IMAGENETTE_CLASSES,
VOC_CLASSES,
)
def coco_yolo_2017_mapping(labels: Iterable[Tensor]):
class_names = [val f... | null |
21,339 | from typing import Any, Dict, Iterable
import numpy
from torch import Tensor
from sparseml.utils.datasets import (
CIFAR_10_CLASSES,
COCO_CLASSES,
COCO_CLASSES_80,
IMAGENET_CLASSES,
IMAGENETTE_CLASSES,
VOC_CLASSES,
)
def apply_box_label_mapping(labels: Iterable[Tensor], class_names: Dict[Any, st... | null |
21,340 | from typing import Any, Dict, Iterable
import numpy
from torch import Tensor
from sparseml.utils.datasets import (
CIFAR_10_CLASSES,
COCO_CLASSES,
COCO_CLASSES_80,
IMAGENET_CLASSES,
IMAGENETTE_CLASSES,
VOC_CLASSES,
)
def apply_box_label_mapping(labels: Iterable[Tensor], class_names: Dict[Any, st... | null |
21,341 | from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
import torch
from packaging import version
from torch.nn import DataParallel, Module
from torch.optim.optimizer import Optimizer
from sparseml.pytorch.utils.helpers import (
download_framework_model_by_recipe_type,
th... | Load the state dict into an optimizer from a given file. :param path: the path to the pth file to load the state dict from :param optimizer: the optimizer to load the state dict into :param map_location: the location to map the values to when loading the :return: the epoch saved in the file, if any |
21,342 | from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
import torch
from packaging import version
from torch.nn import DataParallel, Module
from torch.optim.optimizer import Optimizer
from sparseml.pytorch.utils.helpers import (
download_framework_model_by_recipe_type,
th... | null |
21,343 | from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
import torch
from packaging import version
from torch.nn import DataParallel, Module
from torch.optim.optimizer import Optimizer
from sparseml.pytorch.utils.helpers import (
download_framework_model_by_recipe_type,
th... | Convenience function which traces the provided module using the sample batch into a TorchScript script and saves to provied path. :param path: path to save torchscript :param model: module to convert to TorchScript :param sample_batch: sample batch to trace module with |
21,344 | from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
import torch
from packaging import version
from torch.nn import DataParallel, Module
from torch.optim.optimizer import Optimizer
from sparseml.pytorch.utils.helpers import (
download_framework_model_by_recipe_type,
th... | Convenience function which scripts the provided module into a TorchScript script and saves to provied path. :param path: path to save torchscript :param model: module to convert to torchscript |
21,345 | from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
import torch
from packaging import version
from torch.nn import DataParallel, Module
from torch.optim.optimizer import Optimizer
from sparseml.pytorch.utils.helpers import (
download_framework_model_by_recipe_type,
th... | Save a model's state dict into a file at the given path. Additionally can save an optimizer's state and the current epoch. :param path: the path to save the file the states to :param model: the model to save state for :param optimizer: the optimizer, if any, to save state for :param recipe: the recipe used to obtain th... |
21,346 | from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
import torch
from packaging import version
from torch.nn import DataParallel, Module
from torch.optim.optimizer import Optimizer
from sparseml.pytorch.utils.helpers import (
download_framework_model_by_recipe_type,
th... | The model to push onto a device or multiple devices. :param model: the model to push to a device :param device: the device string to push to; ex: cpu, cuda, cuda:0,1. For DDP, device should be the local_rank int value; ex: 0 :param ddp: set True to wrap module as a DDP object. If True, device should be set to the local... |
21,347 |
The provided code snippet includes necessary dependencies for implementing the `record` function. Write a Python function `def record(func)` to solve the following problem:
Wraps function with pytorch elastic record for error propagation. Introduced in pytorch v1.9 and will return the unmodified function for lesser v... | Wraps function with pytorch elastic record for error propagation. Introduced in pytorch v1.9 and will return the unmodified function for lesser versions |
21,348 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | null |
21,349 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param optim: The optimizer to get the learning rate for :return: convenience function to get the first learning rate for any of the param groups in the optimizer |
21,350 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param optim: The optimizer to get the learning rates for :return: get a list of tuples corresponding to the learning rates for the param groups in the optimizer |
21,351 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param optim: The optimizer to set the learning rate for :param value: the learning rate to set for the optimizer, will set all param groups in the optim to this value |
21,352 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | A never ending data loader that will keep repeating the one passed in. Will additionally cache the data if requested. :param data_loader: the data loader to continually repeat :param early_stop_steps: if set, the number of steps to run and break out early instead of running all of the steps in the data loader :param ca... |
21,353 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | Default function for getting the batch size from a tensor or collection of tensors. Returns the batch size (zeroth index for shape) of the first found tensor. Supported use cases: - single tensor - Dictionary of single tensors - Dictionary of iterable of tensors - Dictionary of dictionary of tensors - Iterable of singl... |
21,354 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param tensors: the tensors to change the precision of :param full_precision: True for full precision (float 32) and False for half (float 16) :return: the tensors converted to the desired precision |
21,355 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param tens: the tensor to calculate the density for :param dim: the dimension(s) to split the calculations over; ex, can split over batch, channels, or combos :return: the density of the input tens, ie the fraction of numbers that are non zero |
21,356 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param tens: the tensor to grab samples from :param sample_size: the number of samples to grab overall if dim is not supplied or per each dim if it is :param dim: the dimension(s) to split the samples over; ex, can split over batch, channels, or combos :return: the sampled tensor |
21,357 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param tensors: the list of tensors to calculate the sparsity for :return: the total sparsity of all tensors in the list |
21,358 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param old_mask: the old mask to compare against for calculating the difference :param new_mask: the new mask to compare with for calculating the difference :return: a tensor representing the change from the old_mask to the new_mask specifically values returned as 1.0 are newly unmasked (0.0 => 1.0) values returned as ... |
21,359 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | General function to replace a layer in a module with the given new one. :param module: the module to replace the layer in :param name: the name of the layer to replace the activation for :param replace: the module to replace the layer with :return: the original layer that was replaced |
21,360 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param module: the module to grab all terminal layers for :return: a list of all of the terminal layers in a model (ie not containers; so convs, linears, activations, etc) |
21,361 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param module: the module to grab all conv layers for :return: a list of all the conv layers in the module |
21,362 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param module: the module to grab all linear layers for :return: a list of all linear layers in the module |
21,363 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param module: the module to get the prunable layers from :return: a list containing the names and modules of the prunable layers (Linear, ConvNd) |
21,364 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param module: the module to get the quantizable layers from :return: a list containing the names and modules of the quantizable layers (Linear, Conv2d, Conv3d) |
21,365 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param module: the module to get the quantized layers from :return: a list containing the names and modules of the quantized layers (Linear, Conv2d, Conv3d) |
21,366 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param param: the name of the param to grab from the layer :param layer: the name of the layer to grab from the module :param module: the module containing the layer and the param :return: the param taken from the given layer in the module |
21,367 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | :param module: the module to get the matching layers and params from :param param_names: a list of names or regex patterns to match with full parameter paths. Regex patterns must be specified with the prefix 're:' :param params_strict: if True, this function will raise an exception if there a parameter is not found to ... |
21,368 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | Manually seeds the numpy, random, and torch packages. Also sets torch.backends.cudnn.deterministic to True :param seed: the manual seed to use. Default is 0 |
21,369 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | Finds a threshold at the lookup idx in the most efficient way with available resources. Will be phased out when GPU-memory overhead of torch.sort reduces, or when torch.kthvalue becomes faster than torch.sort. :param tensor: A tensor to find a k-th smallest value in, where k=idx+1 :param idx: A lookup index :return: k-... |
21,370 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | null |
21,371 | import logging
import os
import random
import re
import warnings
from collections import OrderedDict, namedtuple
from contextlib import contextmanager
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
import numpy
import torch
from packaging import version
from torc... | Get a list of a subset of modules in layer ordered by execution order, which honors the dependencies in the graph :param layer: pytorch module to calculate dependencies for :param subset: subset of modules in the layer to include in the ordering :param an_input: example input to pass through the layer forward pass, use... |
21,372 | from typing import Optional
import torch
from sparseml.pytorch.utils.logger import BaseLogger
from sparseml.pytorch.utils.sparsification_info.module_sparsification_info import (
ModuleSparsificationInfo,
)
class BaseLogger(ABC):
"""
Base class that all modifier loggers must implement.
:param name: nam... | Log the sparsification information for the given module to the given logger :param module: the module to log the sparsification information for :param logger: the logger to log the sparsification information to :param step: the global step for when the sparsification information is being logged. By default, is None |
21,373 | from typing import List, Optional, Union
import torch
from torch.nn.modules.linear import Identity
from torch.quantization import QuantWrapper
The provided code snippet includes necessary dependencies for implementing the `get_leaf_operations` function. Write a Python function `def get_leaf_operations( model: torc... | Get the leaf operations in the model (those that do not have operations as children) :param model: the model to get the leaf operations from :param operations_to_skip: a list of leaf operations that will be omitted when getting the leaf operations. If None passed, by default the Identity operation will be skipped :para... |
21,374 | from typing import List, Optional, Union
import torch
from torch.nn.modules.linear import Identity
from torch.quantization import QuantWrapper
The provided code snippet includes necessary dependencies for implementing the `is_quantized` function. Write a Python function `def is_quantized(operation: torch.nn.Module) ->... | Check whether the operation is quantized (contains a quantization scheme) |
21,375 | from typing import List, Optional, Union
import torch
from torch.nn.modules.linear import Identity
from torch.quantization import QuantWrapper
def _get_num_bits(dtype: torch.dtype) -> int:
# Get the number of bits of a torch dtype
if dtype == torch.float16 or dtype == torch.bfloat16:
return 16
elif ... | Get the information about the precision of the operation. 1) If operation is quantized, returns the quantization scheme of the operation. 2) If operation is not quantized, returns the numer of bits of the operation's weights. 3) If operation is not quantized and does not have a weights, returns None. :param operation: ... |
21,376 | from typing import Iterable, List, Tuple
import torch
from torch import Tensor
The provided code snippet includes necessary dependencies for implementing the `get_output_grid_shapes` function. Write a Python function `def get_output_grid_shapes(outputs: List[Tensor]) -> List[Tensor]` to solve the following problem:
:p... | :param outputs: List of Yolo model outputs :return: A list of the grid dimensions for each of the Yolo outputs |
21,377 | from typing import Iterable, List, Tuple
import torch
from torch import Tensor
The provided code snippet includes necessary dependencies for implementing the `yolo_v3_anchor_groups` function. Write a Python function `def yolo_v3_anchor_groups() -> List[Tensor]` to solve the following problem:
:return: List of the defa... | :return: List of the default anchor coordinate groups for Yolo V3 outputs |
21,378 | from typing import Iterable, List, Tuple
import torch
from torch import Tensor
def _width_height_iou(wh_a: Tensor, wh_b: Tensor) -> Tensor:
# [n,2], [m,2] -> [n,m]
wh_a = wh_a.unsqueeze(1)
wh_b = wh_b.unsqueeze(0)
area_a = wh_a.prod(2)
area_b = wh_b.prod(2)
intersection = torch.min(wh_a, wh_b).p... | Returns a representation of the image targets according to the given anchor groups and grid shapes. :param targets: Yolo data targets tensor of shape n,6 with columns image number, class, center_x, center_y, width, height :param anchors_groups: List of n,2 Tensors of anchor point coordinates for each of the Yolo model'... |
21,379 | from typing import Iterable, List, Tuple
import torch
from torch import Tensor
The provided code snippet includes necessary dependencies for implementing the `box_giou` function. Write a Python function `def box_giou(boxes_a: Tensor, boxes_b: Tensor) -> Tensor` to solve the following problem:
:param boxes_a: 4,N Tenso... | :param boxes_a: 4,N Tensor of xywh bounding boxes :param boxes_b: 4,N Tensor of xywh bounding boxes :return: Shape N Tensor of GIoU values between boxes in the input tensors |
21,380 | from typing import Iterable, List, Tuple
import torch
from torch import Tensor
class YoloGrids(object):
"""
Helper class to compute and store Yolo output and anchor box grids
:param anchor_groups: List of n,2 tensors of the Yolo model's anchor points
for each output group. Defaults to yolo_v3_anchor... | Decode the outputs of a Yolo model and perform non maximum suppression on the predicted boxes. :param preds: list of Yolo model output tensors :param input_shape: shape of input image to model. Default is [640, 640] :param yolo_grids: optional YoloGrids object for caching previously used grid shapes :param confidence_t... |
21,381 | import itertools
import math
import random
from collections import defaultdict
from typing import Any, Callable, Dict, List, NamedTuple, Tuple, Union
import numpy
import torch
from PIL import Image
from torch import Tensor
class DefaultBoxes(object):
"""
Convenience class for creating, representing, encoding, a... | Convenience function for generating DefaultBoxes object for standard SSD300 model :param voc: set True if default boxes should be made for VOC dataset. Will set scales to be slightly larger than for the default COCO dataset configuration :return: DefaultBoxes object implemented for standard SSD300 models |
21,382 | import itertools
import math
import random
from collections import defaultdict
from typing import Any, Callable, Dict, List, NamedTuple, Tuple, Union
import numpy
import torch
from PIL import Image
from torch import Tensor
def _ltrb_to_xywh(boxes):
# in-place conversion from ltrb to cx,cy,w,h format
# expected... | null |
21,383 | import itertools
import math
import random
from collections import defaultdict
from typing import Any, Callable, Dict, List, NamedTuple, Tuple, Union
import numpy
import torch
from PIL import Image
from torch import Tensor
def _xywh_to_ltrb_batch(boxes):
# in-place conversion from cx, cy, w, h format to ltrb
#... | null |
21,384 | import itertools
import math
import random
from collections import defaultdict
from typing import Any, Callable, Dict, List, NamedTuple, Tuple, Union
import numpy
import torch
from PIL import Image
from torch import Tensor
_SSD_RANDOM_CROP_OPTIONS = (
# return original
None,
# random crop (all IoUs are vali... | Performs one of the random SSD crops on a given image, bounding boxes, and labels as implemented in the original paper. | Chooses between following 3 conditions: | 1. Preserve the original image | 2. Random crop minimum IoU is among 0.1, 0.3, 0.5, 0.7, 0.9 | 3. Random crop Adapted from: https://github.com/chauhan-utk/s... |
21,385 | import time
from abc import ABC, abstractmethod
from collections import OrderedDict
from contextlib import ExitStack
from typing import Any, Callable, Dict, List, Optional, Union
import torch
from torch import Tensor
from torch.nn import Module
from torch.optim.optimizer import Optimizer
from torch.utils.data import Da... | Default function to perform a backwards pass for a model and the calculated losses Calls backwards for the DEFAULT_LOSS_KEY in losses Dict :param model: the model to run the backward for :param losses: the losses dictionary containing named tensors, DEFAULT_LOSS_KEY is expected to exist and backwards is called on that ... |
21,386 | from typing import Optional
from sparseml.core.utils import session_context_manager
from sparseml.evaluation.registry import SparseMLEvaluationRegistry
from sparsezoo.evaluation.results import Result
class SparseMLEvaluationRegistry(EvaluationRegistry):
"""
This class is used to register and retrieve evaluatio... | Evaluate a target model on a dataset using the specified integration. :param model_path: Path to the model folder or the model stub from SparseZoo/HuggingFace to evaluate. For example, `mgoin/llama2.c-stories15M-quant-pt` :param datasets: The dataset(s) to evaluate on. For example, `open_platypus`. If None, it is left ... |
21,387 | import logging
from typing import Any, Dict, List, Union
from sparseml.evaluation.registry import SparseMLEvaluationRegistry
from sparsezoo.evaluation.results import Dataset, Evaluation, Metric, Result
_LOGGER = logging.getLogger(__name__)
class SparseMLLM(HFLM):
"""
SparseML is an open-source model optimizatio... | Run the lm-evaluation-harness on the given target model :param model-path: the target model to evaluate, can be path to a local model directory or a SparseZoo/Huggingface stub :param datasets: the datasets to evaluate on, can be a string or list of strings, or a command separated string :param batch_size: the batch siz... |
21,388 | from typing import List, Optional, Union
from sparseml.transformers.utils.sparse_model import SparseAutoModelForCausalLM
from sparseml.transformers.utils.sparse_tokenizer import SparseAutoTokenizer
try:
import numpy
import torch
from datasets import Dataset as HuggingFaceDataset
from datasets import loa... | Perform perplexity evaluation on a language model. :param model_path: The path to the model to evaluate :param datasets: The name of the dataset to evaluate on :param batch_size: The batch size to use for evaluation :param device: The device to use for evaluation :param limit: The number of samples to evaluate on :para... |
21,389 | import importlib
import logging
from contextlib import suppress
from pathlib import Path
from typing import Callable, Dict
import yaml
from sparsezoo.evaluation import EvaluationRegistry
from sparsezoo.evaluation.results import Result
from sparsezoo.utils.registry import standardize_lookup_name
_LOGGER = logging.getLog... | This function is used to collect integrations based on name, this method is responsible for triggering the registration with the SparseML Evaluation registry. This is done by importing the module associated with each integration. This function is called automatically when the registry is accessed. The specific integrat... |
21,390 | import functools
from typing import Optional
from sparseml.base import check_version
def check_deepsparse_install(
min_version: Optional[str] = None,
max_version: Optional[str] = None,
raise_on_error: bool = True,
) -> bool:
"""
Check that the deepsparse package is installed.
If raise_on_error, ... | Decorator function to require use of deepsparse. Will check that deepsparse package is installed and within the bounding ranges of min_version and max_version if they are set before calling the wrapped function. See :func:`check_deepsparse_install` for more info. param min_version: The minimum version for deepsparse th... |
21,391 | import logging
from sparseml.sparsification import SparsificationInfo
_LOGGER = logging.getLogger(__name__)
The provided code snippet includes necessary dependencies for implementing the `sparsification_info` function. Write a Python function `def sparsification_info() -> SparsificationInfo` to solve the following pro... | Load the available setup for sparsifying model within deepsparse. :return: The sparsification info for the deepsparse framework :rtype: SparsificationInfo |
21,392 | import logging
from typing import Any
from sparseml.base import Framework, get_version
from sparseml.deepsparse.base import check_deepsparse_install
from sparseml.deepsparse.sparsification import sparsification_info
from sparseml.framework import FrameworkInferenceProviderInfo, FrameworkInfo
from sparseml.sparsificatio... | :param item: The item to detect the support for :type item: Any :return: True if the item is supported by deepsparse, False otherwise :rtype: bool |
21,393 | import logging
from typing import Any
from sparseml.base import Framework, get_version
from sparseml.deepsparse.base import check_deepsparse_install
from sparseml.deepsparse.sparsification import sparsification_info
from sparseml.framework import FrameworkInferenceProviderInfo, FrameworkInfo
from sparseml.sparsificatio... | Detect the information for the deepsparse framework such as package versions, availability for core actions such as training and inference, sparsification support, and inference provider support. :return: The framework info for deepsparse :rtype: FrameworkInfo |
21,394 | import argparse
import logging
import os
from typing import Optional
import torch
import openpifpaf
from sparseml.pytorch.optim.manager import ScheduledModifierManager
from sparseml.pytorch.utils import ModuleExporter
from sparsezoo.utils import validate_onnx
def image_size_warning(basenet_stride, input_w, input_h):
... | null |
21,395 | import argparse
import copy
import logging
import os
import socket
from typing import Dict, Optional, Tuple
import torch
import openpifpaf
from openpifpaf import __version__
from openpifpaf.train import default_output_file
from sparseml.openpifpaf.trainer import SparseMLTrainer
from sparseml.pytorch.optim.manager impor... | null |
21,396 | import argparse
import copy
import logging
import os
import socket
from typing import Dict, Optional, Tuple
import torch
import openpifpaf
from openpifpaf import __version__
from openpifpaf.train import default_output_file
from sparseml.openpifpaf.trainer import SparseMLTrainer
from sparseml.pytorch.optim.manager impor... | null |
21,397 | import functools
from typing import Optional
from sparseml.base import check_version
_ONNX_MIN_VERSION = "1.5.0"
def check_onnx_install(
min_version: Optional[str] = _ONNX_MIN_VERSION,
max_version: Optional[str] = None,
raise_on_error: bool = True,
) -> bool:
"""
Check that the onnx package is insta... | Decorator function to require use of onnx. Will check that onnx package is installed and within the bounding ranges of min_version and max_version if they are set before calling the wrapped function. See :func:`check_onnx_install` for more info. param min_version: The minimum version for onnx that it must be greater th... |
21,398 | import functools
from typing import Optional
from sparseml.base import check_version
_ORT_MIN_VERSION = "1.0.0"
def check_onnxruntime_install(
min_version: Optional[str] = _ORT_MIN_VERSION,
max_version: Optional[str] = None,
raise_on_error: bool = True,
) -> bool:
"""
Check that the onnxruntime pack... | Decorator function to require use of onnxruntime. Will check that onnxruntime package is installed and within the bounding ranges of min_version and max_version if they are set before calling the wrapped function. See :func:`check_onnxruntime_install` for more info. param min_version: The minimum version for onnxruntim... |
21,399 | import logging
from typing import Any, Dict, Generator, List, Optional, Set, Tuple
import numpy
from onnx import ModelProto, numpy_helper
from sparseml.onnx.utils import DataLoader, DeepSparseAnalyzeModelRunner, ONNXGraph
from sparseml.optim import default_pruning_sparsities_perf
from sparseml.sparsification import Ana... | :return: list of ONNX Analyzer implementations |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.