repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
pytorch | pytorch-main/torch/distributed/checkpoint/planner_helpers.py | from typing import Any, List
import torch
from torch.distributed._shard.metadata import ShardMetadata
from torch.distributed._shard.sharded_tensor import ShardedTensor
from torch.distributed._shard.sharded_tensor.metadata import TensorProperties
from torch.distributed._tensor import DTensor
from torch.distributed._te... | 9,020 | 32.287823 | 93 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/_fsspec_filesystem.py | # Mypy will not try inferring the types of any 3rd party libraries installed.
# mypy: ignore-errors
import collections
import dataclasses
import io
import os
import pickle
import queue
import threading
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Callable, cast, Dict, List,... | 15,568 | 29.768775 | 113 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/storage.py | import abc
from dataclasses import dataclass
from typing import List, Any
from torch.futures import Future
from .metadata import (
Metadata,
MetadataIndex,
)
from .planner import (
LoadPlan,
SavePlan,
SavePlanner,
LoadPlanner,
)
__all__ = ["WriteResult", "StorageWriter", "StorageReader"]
@... | 7,016 | 28.987179 | 99 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/metadata.py | from dataclasses import dataclass, field
from typing import Dict, List, Union, Optional, Sequence, Any
from torch.distributed._shard.sharded_tensor.metadata import TensorProperties
import torch
from torch.distributed._shard.sharded_tensor import (
ShardedTensor,
)
__all__ = [
"ChunkStorageMetadata",
"Tens... | 2,378 | 25.730337 | 101 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/resharding.py | from typing import List, Tuple
from torch.distributed.checkpoint.metadata import (
ChunkStorageMetadata
)
__all__: List[str] = []
def _check_shard_metadata_pair_overlap(shard1: ChunkStorageMetadata, shard2: ChunkStorageMetadata):
"""
Checks if two shards overlap.
"""
# For each dim of each shard... | 2,341 | 31.082192 | 99 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/utils.py | import os
import io
from typing import (
List,
Callable,
Optional,
Union,
TypeVar,
Dict,
Any,
cast,
Sequence,
)
import torch.distributed as dist
from .api import (
CheckpointException,
_wrap_exception,
_is_wrapped_exception,
WRAPPED_EXCEPTION,
)
import torch
from to... | 12,209 | 30.147959 | 107 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/_nested_dict.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from typing import Dict, Tuple
from torch.distributed.checkpoint.metadata import (
STATE_DICT_TYPE,
)
from ._traverse import (
traverse_state_dict,
set_element,
OBJ_PATH,
STATE_DICT_ITEM,
)
"""
TODO:
Need to add ability to handle tuple, OrderedD... | 1,854 | 28.919355 | 100 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/default_planner.py | # Copyright (c) Meta Platforms, Inc. and affiliates
import dataclasses
import io
import logging
import operator
from collections import ChainMap
from functools import reduce
from typing import List, Tuple, Dict, Any, Union, cast
import torch
from torch.distributed._shard._utils import narrow_tensor_by_index
from tor... | 14,652 | 32.302273 | 101 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/_sharded_tensor_utils.py | # Copyright (c) Meta Platforms, Inc. and affiliates
import copy
import torch.distributed as dist
from torch.distributed.remote_device import _remote_device
from torch.distributed.checkpoint.metadata import (
STATE_DICT_TYPE,
)
from torch.distributed._shard.sharded_tensor import (
Shard,
ShardMetadata,
... | 4,060 | 32.286885 | 97 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/state_dict_loader.py | from typing import Any, Dict, Optional
import torch
import torch.distributed as dist
from .storage import (
StorageReader,
)
from .planner import LoadPlanner
from .default_planner import DefaultLoadPlanner
from .utils import _DistWrapper
__all__ = ["load_state_dict"]
def load_state_dict(
state_dict: Dict[... | 4,455 | 35.52459 | 94 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/filesystem.py | from abc import ABC, abstractmethod
import queue
import threading
import collections
from dataclasses import dataclass
import os
import dataclasses
import io
import pickle
from typing import List, Union, Dict, cast
import torch
from torch import Tensor
from torch.futures import Future
from pathlib import Path
from .... | 15,436 | 29.568317 | 126 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/state_dict_saver.py | from typing import Optional
import torch
import torch.distributed as dist
from .planner import SavePlanner
from .default_planner import DefaultSavePlanner
from .storage import (
StorageWriter,
)
from .metadata import Metadata, STATE_DICT_TYPE
from .utils import _DistWrapper
__all__ = ["save_state_dict"]
def ... | 4,458 | 33.565891 | 94 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/_traverse.py | # Copyright (c) Meta Platforms, Inc. and affiliates
import torch
from typing import (
Callable,
Collection,
List,
Mapping,
MutableMapping,
Optional,
Tuple,
TypeVar,
Union,
cast,
)
from torch.distributed.checkpoint.metadata import (
STATE_DICT_TYPE,
)
from torch.distributed._... | 5,492 | 31.122807 | 105 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/_dedup_tensors.py | # Copyright (c) Meta Platforms, Inc. and affiliates
import dataclasses
import logging
from typing import Dict, List
from torch.distributed.checkpoint.metadata import MetadataIndex
from torch.distributed.checkpoint.planner import SavePlan
__all__ = ["dedup_tensors"]
def init_logger() -> logging.Logger:
logger = ... | 1,950 | 32.067797 | 107 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/planner.py | import abc
from dataclasses import dataclass
import io
from typing import List, Tuple, Any, Union, Optional
from enum import Enum, auto
import torch
from torch.distributed._shard.sharded_tensor.metadata import TensorProperties
from .metadata import (
ChunkStorageMetadata,
MetadataIndex,
Metadata,
STA... | 13,073 | 33.587302 | 114 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/optimizer.py | # Copyright (c) Meta Platforms, Inc. and affiliates
import dataclasses
from typing import Dict, List, Optional, Sequence, Tuple, Union, cast
from torch.distributed.checkpoint.planner import LoadPlan
import torch
import torch.distributed as dist
from torch.distributed._shard.sharded_tensor.api import ShardedTensor
fro... | 11,726 | 33.59292 | 103 | py |
pytorch | pytorch-main/torch/distributed/checkpoint/examples/fsdp_checkpoint_example.py | # Copyright (c) Meta Platforms, Inc. and affiliates
"""
The following example demonstrates how to use Pytorch Distributed Checkpoint
to save a FSDP model. This is the current recommended way to checkpoint FSDP.
torch.save() and torch.load() is not recommended when checkpointing sharded models.
"""
import os
import sh... | 4,264 | 31.310606 | 85 | py |
pytorch | pytorch-main/torch/distributed/benchmarks/benchmark_ddp_rpc.py | import argparse
import io
import os
import random
import shlex
import subprocess
import time
import numpy as np
import torch
import torch.nn as nn
import torch.distributed as dist
import torch.distributed.autograd as dist_autograd
import torch.distributed.rpc as rpc
import torch.multiprocessing as mp
import torch.opti... | 11,786 | 31.204918 | 102 | py |
pytorch | pytorch-main/torch/distributed/examples/memory_tracker_example.py | import torch
import torchvision
from torch.distributed._tools import MemoryTracker
def run_one_model(net: torch.nn.Module, input: torch.Tensor):
net.cuda()
input = input.cuda()
# Create the memory Tracker
mem_tracker = MemoryTracker()
# start_monitor before the training iteration starts
mem_... | 858 | 25.030303 | 88 | py |
pytorch | pytorch-main/torch/distributed/_tools/memory_tracker.py | from collections import defaultdict
from itertools import chain
import pickle
from typing import (
Any,
Callable,
Dict,
List,
no_type_check,
Sequence,
)
import torch
import torch.nn as nn
from torch.utils.hooks import RemovableHandle
from torch.utils._python_dispatch import TorchDispatchMode... | 11,711 | 35.830189 | 101 | py |
pytorch | pytorch-main/torch/distributed/_sharding_spec/__init__.py | # Keep old package for BC purposes, this file should be removed once
# everything moves to the `torch.distributed._shard` package.
import sys
import torch
import warnings
from torch.distributed._shard.sharding_spec import * # noqa: F403
warnings.warn(
"torch.distributed._sharding_spec will be deprecated, use torc... | 520 | 33.733333 | 110 | py |
pytorch | pytorch-main/torch/distributed/autograd/__init__.py |
import sys
import torch
def is_available():
return hasattr(torch._C, "_dist_autograd_init")
if is_available() and not torch._C._dist_autograd_init():
raise RuntimeError("Failed to initialize torch.distributed.autograd")
if is_available():
from torch._C._distributed_autograd import (
get_gradie... | 1,630 | 29.773585 | 78 | py |
pytorch | pytorch-main/torch/distributed/algorithms/join.py | import warnings
from abc import ABC, abstractmethod
from types import TracebackType
from typing import Any, List, NamedTuple, Optional, Type
import torch
import torch.distributed as dist
__all__ = ['JoinHook', 'Joinable', 'Join']
class JoinHook():
r"""
This defines a join hook, which provides two entry point... | 13,546 | 36.946779 | 91 | py |
pytorch | pytorch-main/torch/distributed/algorithms/_checkpoint/checkpoint_wrapper.py | import warnings
from enum import auto, Enum
from functools import partial
from typing import Any, Callable, Dict, Iterator, Optional, Tuple
import torch
import torch.nn as nn
from torch.autograd.graph import save_on_cpu
from torch.distributed.utils import _pack_kwargs, _replace_by_prefix, _unpack_kwargs
from torch.uti... | 12,239 | 38.74026 | 106 | py |
pytorch | pytorch-main/torch/distributed/algorithms/_comm_hooks/default_hooks.py | import functools
import torch
import torch.distributed as dist
from typing import Optional
class DefaultState:
r"""
Stores state needed to perform the default communication algorithm
within a communication hook.
Args:
process_group (ProcessGroup): The process group to be used.
"""
__... | 7,158 | 42.652439 | 124 | py |
pytorch | pytorch-main/torch/distributed/algorithms/_optimizer_overlap/optimizer_overlap.py | from abc import ABC
import inspect
from typing import Dict, Type
from torch.distributed.fsdp import FullyShardedDataParallel
from torch.nn.parallel import DistributedDataParallel
from torch.optim import Optimizer
from torch.distributed.optim import as_functional_optim
from torch.distributed.algorithms.ddp_comm_hooks.... | 3,386 | 37.488636 | 89 | py |
pytorch | pytorch-main/torch/distributed/algorithms/_quantization/quantization.py | import functools
import torch
import torch.distributed as dist
from enum import Enum
TORCH_HALF_MIN = torch.finfo(torch.float16).min
TORCH_HALF_MAX = torch.finfo(torch.float16).max
class DQuantType(Enum):
"""
Different quantization methods for auto_quantize API are identified here.
auto_quantize API cu... | 5,621 | 38.041667 | 108 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/optimizer_overlap_hooks.py | from typing import Any, Callable, List, no_type_check
import torch
import torch.distributed as dist
from torch.autograd import Variable
from functools import partial
from dataclasses import dataclass
__all__: List[str] = []
_FUNCTIONAL_OPTIM_STEP_METHOD_NAME = "step_param"
class _OptimizerHookState:
"""
Hol... | 6,030 | 38.162338 | 91 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/mixed_precision_hooks.py | import torch
import torch.distributed as dist
from torch.autograd import Variable
from dataclasses import dataclass
from typing import Any, no_type_check
from torch.distributed.utils import _free_storage
@dataclass
class _AllreduceUpcastHookState:
"""
State to manage DDP mixed precision in backward / gradient... | 3,306 | 39.329268 | 95 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/powerSGD_hook.py | from collections import defaultdict
import logging
import math
from typing import Dict
import torch
import torch.distributed as dist
from . import default_hooks as default
from torch.distributed import distributed_c10d
__all__ = [
"PowerSGDState", "powerSGD_hook", "batched_powerSGD_hook"
]
logger = logging.getL... | 40,020 | 46.700834 | 578 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/ddp_zero_hook.py | import weakref
from typing import Any, Callable, List, Optional
import torch
import torch.distributed as dist
from torch.distributed.optim import ZeroRedundancyOptimizer
from torch.distributed.optim.zero_redundancy_optimizer import (
_OverlapStatus,
)
from torch.nn.parallel.distributed import DistributedDataParall... | 19,590 | 42.247241 | 89 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/post_localSGD_hook.py | import logging
import torch
import torch.distributed as dist
from . import default_hooks as default
logger = logging.getLogger(__name__)
class PostLocalSGDState:
r"""
Stores the state for all-reducing gradients globally using ``process_group`` until step ``start_localSGD_iter``,
and all-reducing gradie... | 4,834 | 39.630252 | 127 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/__init__.py | from enum import Enum
from functools import partial
import torch.distributed as dist
from . import (
debugging_hooks as debugging,
default_hooks as default,
powerSGD_hook as powerSGD,
quantization_hooks as quantization,
optimizer_overlap_hooks as optimizer_overlap,
)
__all__ = ['DDPCommHookType',... | 3,390 | 31.92233 | 113 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/quantization_hooks.py | import torch
import torch.distributed as dist
from torch import nn
def _quantize_per_tensor_cuda(x, scale, zero_point):
y = torch.round(x / scale) + zero_point
y = torch.clamp(y, 0, 255).to(torch.uint8)
return y
def _dequantize_per_tensor_cuda(y, scale, zero_point):
x = scale * (y.to(torch.float32) ... | 8,206 | 36.99537 | 95 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/default_hooks.py | from typing import Any, Callable
import torch
import torch.distributed as dist
__all__ = ["allreduce_hook", "fp16_compress_hook", "bf16_compress_hook", "fp16_compress_wrapper", "bf16_compress_wrapper"]
def _allreduce_fut(
process_group: dist.ProcessGroup, tensor: torch.Tensor
) -> torch.futures.Future[torch.Tens... | 7,591 | 40.037838 | 123 | py |
pytorch | pytorch-main/torch/distributed/algorithms/ddp_comm_hooks/debugging_hooks.py | from typing import Any
import torch
from torch.distributed import GradBucket
__all__ = ["noop_hook"]
def noop_hook(_: Any, bucket: GradBucket) -> torch.futures.Future[torch.Tensor]:
"""
This DDP communication hook returns a future that wraps the input,
so it is a noop that does not incur any communicati... | 1,146 | 37.233333 | 110 | py |
pytorch | pytorch-main/torch/distributed/algorithms/model_averaging/utils.py | # flake8: noqa C101
import itertools
from typing import Union, Iterable, Dict, Iterator
import torch
import torch.distributed as dist
# The two imports below are not always available depending on the
# USE_DISTRIBUTED compile flag. Make sure they raise import error
# if we're trying to use them.
from torch.distributed... | 3,022 | 40.986111 | 158 | py |
pytorch | pytorch-main/torch/distributed/algorithms/model_averaging/averagers.py | import warnings
from abc import ABC, abstractmethod
from typing import Union, Iterable, Dict
import torch
import torch.distributed as dist
import torch.distributed.algorithms.model_averaging.utils as utils
__all__ = ['ModelAverager', 'PeriodicModelAverager']
class ModelAverager(ABC):
r"""Base class for all model ... | 5,204 | 42.375 | 119 | py |
pytorch | pytorch-main/torch/distributed/algorithms/model_averaging/hierarchical_model_averager.py | # Copyright 2022 Cruise LLC
import logging
import warnings
from collections import OrderedDict
from typing import Union, Iterable, Dict
import torch
import torch.distributed as dist
import torch.distributed.algorithms.model_averaging.averagers as averagers
import torch.distributed.algorithms.model_averaging.utils as u... | 9,667 | 57.593939 | 129 | py |
pytorch | pytorch-main/torch/distributed/optim/post_localSGD_optimizer.py | import warnings
import torch
import torch.distributed.algorithms.model_averaging.averagers as averagers
class PostLocalSGDOptimizer(torch.optim.Optimizer):
r"""
Wraps an arbitrary :class:`torch.optim.Optimizer` and runs `post-local SGD <https://arxiv.org/abs/1808.07217>`_,
This optimizer runs local optim... | 4,387 | 38.890909 | 119 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_adam.py | from typing import Dict, List, Optional, Tuple
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional Adam Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating parameter... | 7,055 | 35.75 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_adamw.py | from typing import Dict, List, Optional, Tuple
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional AdamW Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating paramete... | 7,175 | 36.181347 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/apply_optimizer_in_backward.py | from typing import Any, Dict, Iterable, List, no_type_check, Type
import torch
__all__: List[str] = []
# WeakTensorKeyDictionary to store relevant meta-data for the Tensor/Parameter
# without changing it's life-time.
# NOTE: Alternative is to add the meta-data as an attribute to the tensor,
# but that will ser... | 4,034 | 43.340659 | 105 | py |
pytorch | pytorch-main/torch/distributed/optim/utils.py | from typing import Type
from torch import optim
from .functional_adadelta import _FunctionalAdadelta
from .functional_adagrad import _FunctionalAdagrad
from .functional_adam import _FunctionalAdam
from .functional_adamax import _FunctionalAdamax
from .functional_adamw import _FunctionalAdamW
from .functional_rmsprop i... | 2,237 | 33.96875 | 81 | py |
pytorch | pytorch-main/torch/distributed/optim/named_optimizer.py | import logging
import warnings
from copy import deepcopy
from typing import Any, Collection, Dict, List, Mapping, Optional, Union
import torch
import torch.nn as nn
from torch import optim
from torch.distributed._shard.sharded_tensor import ShardedTensor
from torch.distributed.fsdp import FullyShardedDataParallel as ... | 13,852 | 41.363914 | 132 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_adagrad.py | from typing import Dict, List, Optional
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional Adagrad Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating parameters,
#... | 3,855 | 36.076923 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_rmsprop.py | from typing import Dict, List, Optional
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional RMSprop Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating parameters,
#... | 4,285 | 34.716667 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_adadelta.py | from typing import Dict, List, Optional
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional Adadelta Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating parameters,
... | 3,521 | 33.871287 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/__init__.py | """
:mod:`torch.distributed.optim` exposes DistributedOptimizer, which takes a list
of remote parameters (:class:`~torch.distributed.rpc.RRef`) and runs the
optimizer locally on the workers where the parameters live. The distributed
optimizer can use any of the local optimizer :ref:`optimizer-algorithms` to
apply the ... | 1,249 | 39.322581 | 80 | py |
pytorch | pytorch-main/torch/distributed/optim/zero_redundancy_optimizer.py | # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
#
# This source code is licensed under the BSD license found in the
# LICENSE file in the root directory of this source tree.
import collections
import copy
import enum
import inspect
import io
import logging
from itertools import chain
from typin... | 71,665 | 42.3289 | 123 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_rprop.py | from typing import Dict, List, Optional, Tuple
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional Rprop Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating paramete... | 3,447 | 34.183673 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_adamax.py | from typing import Dict, List, Optional, Tuple
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional Adamax Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating paramet... | 4,368 | 36.991304 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/functional_sgd.py | from typing import Dict, List, Optional
import torch
import torch.optim._functional as F
from torch import Tensor
__all__: List[str] = []
# Define a TorchScript compatible Functional SGD Optimizer
# where we use these optimizer in a functional way.
# Instead of using the `param.grad` when updating parameters,
# we ... | 5,478 | 34.810458 | 88 | py |
pytorch | pytorch-main/torch/distributed/optim/optimizer.py | import logging
from collections import defaultdict
from threading import Lock
from typing import List, Optional
import torch
import torch.distributed.autograd as dist_autograd
import torch.distributed.rpc as rpc
import torch.jit as jit
import torch.nn as nn
from torch import Tensor
from torch.distributed.rpc import R... | 9,807 | 37.614173 | 90 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/style.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from abc import ABC, abstractmethod
from typing import Optional, Union
import torch
from torch.distributed._tensor import DeviceMesh, DTensor, Replicate, Shard
from torch.distributed.tensor.parallel._utils import (
_prepare_input_validate,
_prepare_output_val... | 12,607 | 35.758017 | 115 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/_utils.py | import functools
from typing import Callable, Optional, Union
import torch
from torch.distributed._tensor import DeviceMesh, DTensor
_PrepareInputType = Callable[
[Union[torch.Tensor, DTensor], Optional[DeviceMesh], Optional[int]], DTensor
]
_PrepareOutputType = Callable[
[DTensor, Optional[DeviceMesh], Opti... | 5,407 | 33.666667 | 91 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/multihead_attention_tp.py | # Copyright (c) Meta Platforms, Inc. and affiliates
# pyre-ignore-all-errors[6]
import math
from typing import Optional, Union
import torch
from torch.distributed._tensor import DTensor as DT
from torch.distributed._tensor.placement_types import Shard
from torch.distributed.tensor.parallel._view_with_dim_change impo... | 10,194 | 36.208029 | 86 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/api.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from typing import Dict, Union
import torch
import torch.nn as nn
import torch.distributed._tensor.random as random
from torch.distributed._tensor import (
DeviceMesh,
DTensor,
distribute_module,
distribute_tensor,
Replicate,
Shard,
)
from tor... | 16,236 | 35.162584 | 106 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/_view_with_dim_change.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from typing import Tuple, Union, Sequence, cast
import torch
from torch.distributed._tensor import DeviceMesh
from torch.distributed._tensor import DTensor as DT
from torch.distributed._tensor.ops.utils import prod
from torch.distributed._tensor.placement_types impor... | 5,574 | 37.986014 | 105 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/fsdp.py | import copy
import warnings
from typing import cast, List, NamedTuple, Optional, Tuple
import torch
import torch.distributed as dist
import torch.distributed._shard.sharding_spec as shard_spec
import torch.distributed.distributed_c10d as c10d
from torch.distributed.fsdp._common_utils import _set_fsdp_flattened
from ... | 11,251 | 30.518207 | 102 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/__init__.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from torch.distributed.tensor.parallel.api import parallelize_module
from torch.distributed.tensor.parallel.multihead_attention_tp import (
TensorParallelMultiheadAttention,
)
from torch.distributed.tensor.parallel.style import (
ColwiseParallel,
make_inp... | 1,140 | 26.166667 | 70 | py |
pytorch | pytorch-main/torch/distributed/tensor/parallel/input_reshard.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from functools import partial
from typing import Any, Optional, Tuple
import torch
from torch.distributed._tensor import DeviceMesh, DTensor, Replicate, Shard
__all__ = [
"input_reshard",
]
def input_reshard(
module: torch.nn.Module,
tp_device_mesh: De... | 3,623 | 32.869159 | 93 | py |
pytorch | pytorch-main/torch/distributed/_spmd/data_parallel.py | import operator
from contextlib import contextmanager
from enum import Enum
from typing import Any, cast, Dict, List, Optional, Tuple
import torch
import torch.distributed.distributed_c10d as c10d
import torch.fx as fx
import torch.library
import torch.nn as nn
import torch.utils._pytree as pytree
from torch.distr... | 38,013 | 43.933806 | 123 | py |
pytorch | pytorch-main/torch/distributed/_spmd/iter_graph_module.py | import copy
import inspect
import logging
from typing import Any, Callable, cast, Dict, List, Optional, Set, Tuple, Type
import torch.nn as nn
from torch import fx
from torch.distributed._spmd.graph_utils import (
clone_subgraph,
get_output,
is_leaf_subgraph,
)
from torch.distributed._spmd.partial_lower im... | 32,142 | 41.07199 | 89 | py |
pytorch | pytorch-main/torch/distributed/_spmd/partial_lower.py | # This file is copied from Meta internal repo and is not synced with the
# internal version. Once the internal version is fully mature, we should
# upstream again and retire the internal version. @yifuwang
import logging
import operator
from typing import Callable, List, Optional, Set, Tuple
from functorch import mak... | 9,899 | 35.802974 | 88 | py |
pytorch | pytorch-main/torch/distributed/_spmd/parallel_mode.py | from abc import ABC, abstractmethod
from typing import Any, Callable, Dict, List, Optional, Tuple
import torch
import torch.distributed as dist
import torch.utils._pytree as pytree
from torch._subclasses import FakeTensorMode
from torch.distributed._spmd.data_parallel import (
DataParallelStyle,
partition_data... | 7,983 | 35.792627 | 86 | py |
pytorch | pytorch-main/torch/distributed/_spmd/api.py | from abc import ABC, abstractmethod
from contextlib import contextmanager, nullcontext
from copy import copy
from dataclasses import dataclass
from functools import partial, wraps
from typing import Any, Callable, cast, Dict, List, Optional, Set, Tuple, Union
from functorch import make_fx
import torch
import torch.di... | 21,014 | 35.803853 | 120 | py |
pytorch | pytorch-main/torch/distributed/_spmd/distribute.py | import logging
import operator
from dataclasses import dataclass
from enum import auto, Enum
from functools import partial
from typing import Any, Callable, cast, Dict, List, Optional, Sequence, Tuple, Union
import torch
import torch.distributed._spmd.experimental_ops
import torch.fx as fx
from torch.distributed._spm... | 30,348 | 37.465146 | 100 | py |
pytorch | pytorch-main/torch/distributed/_spmd/comm_tensor.py | from dataclasses import dataclass
from functools import partial
from typing import Any, List, Optional, Tuple
import torch
from torch._C import _disabled_torch_function_impl
from torch.fx.experimental.proxy_tensor import (
_ProxyTensor,
fetch_tensor_proxy,
get_innermost_proxy_mode,
get_proxy_slot,
... | 10,220 | 40.380567 | 87 | py |
pytorch | pytorch-main/torch/distributed/_spmd/log_utils.py | import logging
import logging.config
import os
from typing import Optional
import torch.distributed as dist
LOGGING_CONFIG = {
"version": 1,
"formatters": {
"spmd_format": {"format": "%(name)s: [%(levelname)s] %(message)s"},
"graph_opt_format": {"format": "%(name)s: [%(levelname)s] %(message)... | 2,344 | 28.683544 | 92 | py |
pytorch | pytorch-main/torch/distributed/_spmd/graph_utils.py | import logging
import os
import tempfile
from enum import Enum
from typing import Callable, cast, Dict, Iterable, List, Set
import torch.fx as fx
from torch.fx.passes.shape_prop import TensorMetadata
from torch.utils._pytree import tree_flatten, tree_unflatten
logger: logging.Logger = logging.getLogger("graph_utils"... | 4,911 | 31.746667 | 93 | py |
pytorch | pytorch-main/torch/distributed/_spmd/experimental_ops.py | # Copyright (c) Meta Platforms, Inc. and affiliates
from typing import cast, List, Optional, Sequence, Tuple
import torch
from torch.distributed._tensor.op_schema import OpSchema, OutputSharding
from torch.distributed._tensor.ops.common_rules import pointwise_rule
from torch.distributed._tensor.ops.utils import regist... | 18,273 | 37.634249 | 104 | py |
pytorch | pytorch-main/torch/distributed/_spmd/batch_dim_utils.py | from typing import Callable, Dict, List, Set
import torch
import torch.fx as fx
import torch.utils._pytree as pytree
from torch import Tensor
from torch.distributed._tensor import DeviceMesh, Replicate, Shard
from torch.distributed._tensor.ops.view_ops import (
DimSpec,
InputDim,
ops as view_op_rules,
... | 7,977 | 41.663102 | 95 | py |
pytorch | pytorch-main/torch/distributed/_spmd/graph_optimization.py | # Owner(s): ["oncall: distributed"]
import collections
import itertools
import logging
import operator
import tempfile
import time
from dataclasses import dataclass, field
from functools import wraps
from typing import (
Any,
Callable,
cast,
DefaultDict,
Dict,
Iterable,
List,
Optional,
... | 37,819 | 36.82 | 88 | py |
pytorch | pytorch-main/torch/distributed/_spmd/gm_transformation.py | from typing import Callable
from torch import fx
from torch.distributed._spmd.graph_optimization import (
comm_fusion_with_concat,
enable_graph_optimization_dump,
remove_copy_from_optimizer,
schedule_comm_wait,
)
from torch.distributed._spmd.graph_utils import dump_graphs_to_files
from torch.distribute... | 1,793 | 33.5 | 86 | py |
pytorch | pytorch-main/torch/distributed/launcher/api.py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its 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 sys
import uuid
from dataclasses import dataclass, field
from typing import Any, Ca... | 11,002 | 37.607018 | 107 | py |
pytorch | pytorch-main/torch/distributed/launcher/__init__.py | #!/usr/bin/env/python3
# Copyright (c) Facebook, Inc. and its 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.distributed.launcher.api import ( # noqa: F401
LaunchConfig,
elastic... | 349 | 22.333333 | 71 | py |
pytorch | pytorch-main/torch/distributed/fsdp/fully_sharded_data_parallel.py | import contextlib
import copy
import functools
import math
import traceback
import warnings
from contextlib import contextmanager
from enum import auto, Enum
from typing import (
Any,
Callable,
Dict,
Generator,
Iterable,
Iterator,
List,
Optional,
Tuple,
Union,
)
import torch
imp... | 93,770 | 45.467294 | 123 | py |
pytorch | pytorch-main/torch/distributed/fsdp/flat_param.py | import contextlib
import functools
import logging
import os
import warnings
from enum import auto, Enum
from itertools import accumulate, chain
from typing import (
Any,
Callable,
cast,
Dict,
Generator,
Iterator,
List,
NamedTuple,
no_type_check,
Optional,
Sequence,
Set,
... | 113,660 | 43.433542 | 114 | py |
pytorch | pytorch-main/torch/distributed/fsdp/sharded_grad_scaler.py | import logging
from collections import abc, defaultdict
from typing import Dict, List, Optional, Union
import torch
import torch.distributed as dist
from torch.cuda import FloatTensor # type: ignore[attr-defined]
from torch.cuda.amp.grad_scaler import _MultiDeviceReplicator, GradScaler, OptState
from torch.distribute... | 17,073 | 44.652406 | 118 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_shard_utils.py | import itertools
import math
from typing import Any, Dict, Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
from torch.distributed import distributed_c10d
from torch.distributed._shard.sharded_tensor import (
Shard,
ShardedTensor,
ShardedTensorMetadata,
TensorPrope... | 5,998 | 35.803681 | 118 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_trace_utils.py | import functools
from contextlib import contextmanager
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Set, Tuple
import torch
import torch.nn as nn
@dataclass
class TracingConfig:
"""
This represents a symbolic tracing configuration.
Args:
t... | 10,548 | 43.323529 | 97 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_state_dict_utils.py | import contextlib
import logging
import math
import warnings
from typing import Any, Callable, cast, Dict, Generator, Iterator, no_type_check, Tuple
import torch
import torch.distributed as dist
import torch.distributed.algorithms._checkpoint.checkpoint_wrapper as checkpoint_wrapper
import torch.nn as nn
import torc... | 31,869 | 35.758939 | 96 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_utils.py | import weakref
from functools import partial
from typing import Any, Dict, Iterable, Set, Type
import torch
import torch.nn as nn
from torch.distributed.utils import _apply_to_tensors
from torch.utils._mode_utils import no_dispatch
# Save a global mapping from module to its input tensor dtype to be populated
# duri... | 3,861 | 44.435294 | 87 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_init_utils.py | import collections
import itertools
import os
import warnings
from typing import (
Any,
Callable,
Deque,
Dict,
Generator,
Iterable,
Iterator,
List,
no_type_check,
Optional,
Set,
Tuple,
Union,
)
import torch
import torch.distributed as dist
import torch.distributed.fs... | 40,841 | 37.934223 | 109 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_unshard_param_utils.py | import contextlib
import warnings
from typing import cast, Generator, List
import torch
import torch.distributed.fsdp._traversal_utils as traversal_utils
import torch.nn as nn
from torch.distributed.fsdp._common_utils import (
_FSDPState,
_has_fsdp_params,
_module_handles,
HandleTrainingState,
Trai... | 13,003 | 34.145946 | 110 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_debug_utils.py | from typing import Dict, List, Tuple
import torch
import torch.distributed.fsdp.flat_param as flat_param_file
from torch.distributed.fsdp._common_utils import (
_apply_to_modules,
_get_module_fsdp_state,
clean_tensor_name,
)
def _get_sharded_module_tree_with_module_name_to_fqns(
model: torch.nn.Modul... | 4,155 | 38.961538 | 128 | py |
pytorch | pytorch-main/torch/distributed/fsdp/api.py | """
This file includes public APIs for FSDP such as the classes used for the
constructor arguments.
"""
from dataclasses import dataclass
from enum import auto, Enum
from typing import Optional, Sequence
import torch
from torch.nn.modules.batchnorm import _BatchNorm
__all__ = [
"ShardingStrategy",
"Backward... | 15,961 | 43.96338 | 116 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_traversal_utils.py | """
NOTE: This file must be imported like
``import torch.distributed.fsdp._traversal_utils`` and not like
``from torch.distirbuted.fsdp._traversal_utils import ...`` to avoid circular
imports. For brevity, we may import the file as ``traversal_utils``.
"""
import collections
from typing import Deque, List, Set, Tuple
... | 4,538 | 40.263636 | 84 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_exec_order_utils.py | import itertools
import warnings
from enum import auto, Enum
from typing import Dict, List, Optional, Tuple, Union
import torch
import torch.distributed as dist
import torch.distributed.fsdp._traversal_utils as traversal_utils
import torch.nn as nn
from torch.distributed.fsdp._common_utils import _FSDPState, _get_para... | 16,571 | 42.382199 | 129 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_wrap_utils.py | import functools
import inspect
import warnings
from functools import partial
from typing import Any, Callable, Dict, Set, Type, Union
import torch.nn as nn
from torch.distributed.fsdp._common_utils import _get_module_fsdp_state
from torch.distributed.fsdp._utils import _override_module_mixed_precision
from torch.dis... | 4,620 | 36.877049 | 90 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_runtime_utils.py | import functools
import logging
from enum import auto, Enum
from itertools import chain
from typing import Any, Callable, Dict, List, no_type_check, Optional, Set, Tuple
import torch
import torch.distributed as dist
import torch.distributed.fsdp._traversal_utils as traversal_utils
import torch.nn as nn
import torch.nn... | 65,414 | 40.852207 | 113 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_fsdp_extensions.py | from abc import ABC, abstractmethod
from typing import Any, List, Optional, Tuple
import torch
import torch.distributed as dist
from torch.distributed._shard.sharded_tensor.api import ShardedTensor
from torch.distributed._shard.sharded_tensor.shard import Shard
from torch.distributed._tensor.device_mesh import DeviceM... | 3,658 | 25.904412 | 77 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_optim_utils.py | import copy
import functools
import warnings
from dataclasses import dataclass, field
from typing import (
Any,
cast,
Dict,
Iterable,
Iterator,
List,
NamedTuple,
Optional,
Sequence,
Set,
Tuple,
Union,
)
import torch
import torch.distributed as dist
import torch.distribut... | 66,487 | 39.765175 | 110 | py |
pytorch | pytorch-main/torch/distributed/fsdp/wrap.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the BSD license found in the
# LICENSE file in the root directory of this source tree.
import contextlib
import copy
import functools
from abc import ABC, abstractmethod
from typing import (
Any,
Callable,
cast,
D... | 20,104 | 35.755027 | 111 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_limiter_utils.py | import collections
from typing import Deque, Optional
import torch
class _FreeEventQueue:
"""
This tracks all pending frees corresponding to inflight all-gathers. The
queueing pattern is iterative enqueues with a single dequeue per iteration
once the limit ``_max_num_inflight_all_gathers`` is reached... | 1,101 | 31.411765 | 78 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_dynamo_utils.py | from typing import Set
import torch.nn as nn
def _annotate_modules_for_dynamo(
module: nn.Module,
ignored_modules: Set[nn.Module],
use_orig_params: bool,
):
"""
Annotates the submodules in ``module`` 's tree, except those in
``ignored_modules``, indicating that the submodules are FSDP-managed... | 2,647 | 56.565217 | 114 | py |
pytorch | pytorch-main/torch/distributed/fsdp/_common_utils.py | """
This file includes private common utilities for FSDP.
"""
import traceback
import warnings
from enum import auto, Enum
from typing import (
Any,
Callable,
cast,
Dict,
Generator,
Iterable,
List,
no_type_check,
Optional,
Set,
Tuple,
)
import torch
import torch.distributed... | 16,894 | 37.137698 | 115 | py |
pytorch | pytorch-main/torch/distributed/_shard/_utils.py | import torch
from torch.distributed._shard.metadata import ShardMetadata
from typing import Sequence
DEPRECATE_MSG = "Please use DTensor instead and we are deprecating ShardedTensor."
def narrow_tensor_by_index(tensor: torch.Tensor, offsets: Sequence[int], sizes: Sequence[int]) -> torch.Tensor:
"""
Narrow the... | 1,104 | 37.103448 | 111 | py |
pytorch | pytorch-main/torch/distributed/_shard/metadata.py | from dataclasses import dataclass
from typing import List, Union, Optional
from functools import reduce
from torch.distributed.remote_device import _remote_device
@dataclass
class ShardMetadata:
"""
Represents a shard of the overall Tensor including its
offsets, lengths and device placement.
Args:
... | 2,179 | 34.16129 | 80 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.