python_code
stringlengths
0
229k
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from torchdata._utils import ExceptionWrapper class DataLoaderQueueMessage: pass class Request(DataLoad...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import List, Optional, Tuple # Note [Philox Engine implementation] # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from torchdata.dataloader2.random.distributed import dist_share_seed from torchdata.dataloader2.random.seed_gen...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Optional import torch import torch.distributed as dist _HALF_UINT64 = 0x8000000000000000 ...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Optional, Tuple import torch from torchdata.dataloader2.random._philox import PhiloxEngine...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from torch.utils.data import DataChunk, functional_datapipe from . import iter, map, utils __all__ = ["DataCh...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. ############################################################################### # Reference From PyTorch Core #...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Iterator, Optional, TypeVar from torch.utils.data.datapipes.iter.sharding import SHARDING_P...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import re from typing import Any, Dict, Iterator, List, Union from torchdata.datapipes import functional_datap...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import lzma import warnings from io import BufferedIOBase from typing import Iterable, Iterator, Tuple from to...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import contextlib import csv from typing import IO, Iterator, Tuple, TypeVar, Union from torchdata.datapipes i...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Iterator, Optional, TypeVar from warnings import warn from torchdata.datapipes import funct...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from collections import defaultdict from typing import Dict, Iterator, List, Union from torchdata.datapipes im...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import os import sys import warnings import zipfile from io import BufferedIOBase from typing import cast, IO, ...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Dict, Iterator, Tuple, TypeVar from torchdata.datapipes import functional_datapipe from tor...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import random from typing import Dict, Iterator, Optional, Sized, TypeVar from torchdata.datapipes.iter import...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import hashlib from io import IOBase from typing import Dict, Iterator, Tuple, Union from torchdata.datapipes...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import warnings from typing import Callable, Dict, Optional from torch.utils.data import IterDataPipe, MapDat...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import warnings from collections import OrderedDict from typing import Callable, final, Iterator, List, Option...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import bz2 import gzip import lzma import os import pathlib import tarfile import zipfile from enum import Enu...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import threading import time from collections import deque from typing import Deque, final, Optional, Sized i...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Set, Sized from torch.utils.data.datapipes._decorator import functional_datapipe from torch...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import bz2 import warnings from io import BufferedIOBase from typing import Iterable, Iterator, Tuple from tor...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Callable, final, Iterator, List, Tuple, TypeVar from torch.utils.data.datapipes.utils.commo...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import threading import time from collections import deque from concurrent.futures import Future, ThreadPoolE...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import os from typing import Any, Callable, Iterator, Optional, Tuple, Union from torchdata.datapipes import ...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import io import os.path from typing import Iterator, Tuple from unittest.mock import patch from torchdata.dat...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Any, Iterator, List, Optional, Set, Sized, Tuple from torch.utils.data.datapipes._decorator...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import json from typing import Dict, IO, Iterator, Tuple from torchdata.datapipes import functional_datapipe f...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import hashlib import inspect import os.path import sys import time import uuid import warnings from collectio...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Iterator, Optional, TypeVar from torchdata.datapipes import functional_datapipe from torchd...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from functools import partial from typing import List, Optional, TypeVar from torch.utils.data.datapipes.utils...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import struct import warnings from functools import partial from io import BufferedIOBase from typing import An...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import re from typing import Iterator, List from torchdata.datapipes import functional_datapipe from torchdata...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import os import tarfile import warnings from io import BufferedIOBase from typing import cast, IO, Iterable, I...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import random from typing import Dict, final, List, Optional, TypeVar, Union from torchdata.datapipes import f...
# type: ignore # Generated by the protocol buffer compiler. DO NOT EDIT! # source: example.proto import sys _b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) from google.protobuf import ( descriptor as _descriptor, descriptor_pb2, message as _message, reflection as _re...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from io import BytesIO from typing import Iterator, List, Tuple, Union import torchdata from torch.utils.data...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import re import urllib import warnings from typing import Any, Dict, Iterator, Optional, Tuple import request...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Iterator, Tuple from torchdata.datapipes import functional_datapipe from torchdata.datapipe...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import os import posixpath from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Tuple, ...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Any, Iterator, Tuple from torchdata.datapipes.iter import IterDataPipe from torchdata.data...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import os from typing import Any, Callable, Iterator, List, Optional, Sequence, Tuple, Union from torch.utils...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import asyncio import inspect import random import warnings from collections import deque from concurrent impor...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import heapq import random from dataclasses import dataclass, field from functools import partial from typing ...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import collections def pin_memory_fn(data, device=None): r""" Utility function to move data to pinned...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from torch.utils.data.datapipes.utils.common import StreamWrapper from torchdata.datapipes.utils._visualizatio...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from io import IOBase from typing import Tuple from torchdata.datapipes.utils import StreamWrapper def valid...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import itertools from collections import defaultdict from typing import Optional, Set, TYPE_CHECKING from tor...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from torchdata.datapipes.utils import StreamWrapper def janitor(obj): """ Invokes various `obj` clean...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from torch.utils.data import MapDataPipe from torch.utils.data.datapipes.map import Batcher, Concater, Mapper,...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import List, Optional from torch.utils.data import IterDataPipe, MapDataPipe # @functional_datap...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Any, Dict, TypeVar from torchdata.datapipes import functional_datapipe from torchdata.datap...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. from typing import Optional, Sequence, TypeVar from torchdata.datapipes import functional_datapipe from torchd...
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.
#!/usr/bin/env python3 import typing from typing import Any, Callable, cast, List, Tuple, Union import torch from captum._utils.typing import BaselineType, TargetType, TensorOrTupleOfTensorsGeneric from captum.attr import ( DeepLift, GradientShap, GuidedBackprop, IntegratedGradients, Saliency, ) fr...
#!/usr/bin/env python3 import typing from typing import Any, Callable, cast, List, Tuple, Union import torch from captum._utils.typing import BaselineType, TargetType, TensorOrTupleOfTensorsGeneric from captum.attr import ( Attribution, DeepLift, FeatureAblation, IntegratedGradients, Saliency, ) fr...
from unittest.mock import patch import torch from captum.insights.attr_vis.features import ( _convert_figure_base64, EmptyFeature, FeatureOutput, GeneralFeature, ImageFeature, TextFeature, ) from matplotlib.figure import Figure from tests.helpers.basic import BaseTest class TestTextFeature(Ba...
#!/usr/bin/env python3 import unittest from typing import Callable, List, Union import torch import torch.nn as nn from captum.insights import AttributionVisualizer, Batch from captum.insights.attr_vis.app import FilterConfig from captum.insights.attr_vis.features import BaseFeature, FeatureOutput, ImageFeature from ...
#!/usr/bin/env python3 import collections from typing import List import torch from captum.robust import AttackComparator, FGSM from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.helpers.basic_models import BasicModel, BasicModel_MultiLayer from torch import Tensor def float_metric(model_ou...
#!/usr/bin/env python3 from typing import Any, Callable, List, Optional, Tuple, Union import torch from captum._utils.typing import TensorLikeList, TensorOrTupleOfTensorsGeneric from captum.robust import FGSM from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.helpers.basic_models import Basic...
#!/usr/bin/env python3 from typing import cast, List import torch from captum.robust import MinParamPerturbation from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.helpers.basic_models import BasicModel, BasicModel_MultiLayer from torch import Tensor def inp_subtract(inp: Tensor, ind: int =...
#!/usr/bin/env python3 import torch from captum.robust import PGD from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.helpers.basic_models import BasicModel, BasicModel2, BasicModel_MultiLayer from torch.nn import CrossEntropyLoss class Test(BaseTest): def test_attack_nontargeted(self) ->...
import inspect import os import unittest from functools import partial from typing import Callable, Iterator, List, Optional, Tuple, Union import torch import torch.nn as nn import torch.nn.functional as F from captum.influence import DataInfluence from captum.influence._core.tracincp_fast_rand_proj import ( TracI...
import tempfile from typing import Callable import torch.nn as nn from captum.influence._core.tracincp import TracInCP from captum.influence._core.tracincp_fast_rand_proj import ( TracInCPFast, TracInCPFastRandProj, ) from parameterized import parameterized from tests.helpers.basic import assertTensorAlmostEqu...
import tempfile from typing import Callable import torch import torch.nn as nn from captum.influence._core.tracincp import TracInCP from parameterized import parameterized from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.influence._utils.common import ( _format_batch_into_tuple, bu...
import tempfile from typing import Callable import torch import torch.nn as nn from captum.influence._core.tracincp import TracInCP from captum.influence._core.tracincp_fast_rand_proj import TracInCPFast from parameterized import parameterized from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from test...
import tempfile from typing import Callable import torch.nn as nn from captum.influence._core.tracincp import TracInCP from captum.influence._core.tracincp_fast_rand_proj import TracInCPFast from parameterized import parameterized from tests.helpers.basic import BaseTest from tests.influence._utils.common import ( ...
import os import tempfile from collections import OrderedDict from typing import Callable, cast, Optional import torch import torch.nn as nn import torch.nn.functional as F from captum.influence._core.tracincp import TracInCP from parameterized import parameterized from tests.helpers.basic import assertTensorAlmostEqu...
import os import tempfile from typing import Callable, cast, Optional import torch import torch.nn as nn from captum.influence._core.tracincp import TracInCP from captum.influence._core.tracincp_fast_rand_proj import ( TracInCPFast, TracInCPFastRandProj, ) from parameterized import parameterized from tests.hel...
import io import tempfile import unittest import unittest.mock from typing import Callable import torch.nn as nn from captum.influence._core.tracincp import TracInCP from captum.influence._core.tracincp_fast_rand_proj import TracInCPFast from parameterized import parameterized from tests.helpers.basic import BaseTest ...
import tempfile from typing import Callable import torch import torch.nn as nn from captum.influence._core.tracincp import TracInCP from captum.influence._core.tracincp_fast_rand_proj import ( TracInCPFast, TracInCPFastRandProj, ) from parameterized import parameterized from tests.helpers.basic import assertT...
import tempfile from typing import List import torch import torch.nn as nn from captum.influence._core.similarity_influence import ( cosine_similarity, euclidean_distance, SimilarityInfluence, ) from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from torch.utils.data import Dataset class B...
#!/usr/bin/env fbpython # (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. import unittest import torch from captum.module.gaussian_stochastic_gates import GaussianStochasticGates from parameterized import parameterized_class from tests.helpers.basic import assertTensorAlmostEqual, BaseTest @p...
#!/usr/bin/env python3 import unittest import torch from captum.module.binary_concrete_stochastic_gates import BinaryConcreteStochasticGates from parameterized import parameterized_class from tests.helpers.basic import assertTensorAlmostEqual, BaseTest @parameterized_class( [ {"testing_device": "cpu"}, ...
#!/usr/bin/env python3 from typing import List, Tuple import torch from captum._utils.gradient import ( apply_gradient_requirements, compute_gradients, compute_layer_gradients_and_eval, undo_gradient_requirements, ) from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.helpers.b...
#!/usr/bin/env python3 from typing import cast, List, Tuple import torch from captum._utils.common import ( _format_feature_mask, _get_max_feature_index, _parse_version, _reduce_list, _select_targets, _sort_key_list, safe_div, ) from tests.helpers.basic import ( assertTensorAlmostEqual...
#!/usr/bin/env python3 import torch import torch.nn as nn from captum._utils.gradient import ( _compute_jacobian_wrt_params, _compute_jacobian_wrt_params_with_sample_wise_trick, ) from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.helpers.basic_models import BasicLinearModel2, BasicLi...
#!/usr/bin/env python3 import io import unittest import unittest.mock from captum._utils.progress import NullProgress, progress from tests.helpers.basic import BaseTest class Test(BaseTest): @unittest.mock.patch("sys.stderr", new_callable=io.StringIO) def test_nullprogress(self, mock_stderr) -> None: ...
import glob import tempfile from datetime import datetime from typing import cast, List import torch from captum._utils.av import AV from tests.helpers.basic import assertTensorAlmostEqual, BaseTest from tests.helpers.basic_models import BasicLinearReLULinear from torch.utils.data import DataLoader, Dataset DEFAULT_I...
#!/usr/bin/env python3 import torch from captum._utils.models.linear_model.model import ( SGDLasso, SGDLinearRegression, SGDRidge, ) from tests.helpers.basic import assertTensorAlmostEqual, BaseTest def _evaluate(test_data, classifier): classifier.eval() l1_loss = 0.0 l2_loss = 0.0 n = 0...
#!/usr/bin/env python3 import torch from tests.helpers.basic import assertTensorAlmostEqual, BaseTest class HelpersTest(BaseTest): def test_assert_tensor_almost_equal(self) -> None: with self.assertRaises(AssertionError) as cm: assertTensorAlmostEqual(self, [[1.0]], [[1.0]]) self.asse...
#!/usr/bin/env python3 import unittest from typing import Callable, Tuple import torch from captum._utils.gradient import apply_gradient_requirements from captum._utils.sample_gradient import ( _reset_sample_grads, SampleGradientWrapper, SUPPORTED_MODULES, ) from packaging import version from tests.helper...
import argparse import random from typing import Optional import captum._utils.models.linear_model.model as pytorch_model_module import numpy as np import sklearn.datasets as datasets import torch from tests.utils.test_linear_model import _evaluate from torch.utils.data import DataLoader, TensorDataset def sklearn_d...