python_code
stringlengths
0
1.02M
repo_name
stringlengths
9
48
file_path
stringlengths
5
114
# Copyright 2019 Kakao Brain # # 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. """Utilities for eliminating boilerplate code to handle abstract streams with CPU device. "...
pytorch-master
torch/distributed/pipeline/sync/stream.py
from torch import nn from typing import List def partition_model( module: nn.Sequential, balance: List[int], devices: List[int] = None): """ Given an :class:`nn.Sequential <torch.nn.Sequential>` module, partitions the model across multiple GPU devices according the provided ``balanc...
pytorch-master
torch/distributed/pipeline/sync/utils.py
# -*- coding: utf-8 -*- # Copyright 2019 Kakao Brain # # 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. """The pipeline parallelism of Pipe.""" from queue import Queue fro...
pytorch-master
torch/distributed/pipeline/sync/pipeline.py
# Copyright 2019 Kakao Brain # # 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. """Manipulation of micro-batches.""" import typing from typing import Any, Callable, List, ...
pytorch-master
torch/distributed/pipeline/sync/microbatch.py
# Copyright 2019 Kakao Brain # # 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. """Arbitrary dependency between two autograd lanes.""" from typing import List, Tuple impo...
pytorch-master
torch/distributed/pipeline/sync/dependency.py
# Copyright 2019 Kakao Brain # # 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. """The Pipe interface.""" from collections import OrderedDict from typing import TYPE_CHECK...
pytorch-master
torch/distributed/pipeline/sync/pipe.py
# -*- coding: utf-8 -*- # Copyright 2019 Kakao Brain # # 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. """Portal keeps a tensor in the pocket plane. The tensor becomes hi...
pytorch-master
torch/distributed/pipeline/sync/skip/portal.py
# Copyright 2019 Kakao Brain # # 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. """Static skip connection layout of ``@skippable`` modules.""" from typing import Dict, Ite...
pytorch-master
torch/distributed/pipeline/sync/skip/layout.py
# Copyright 2019 Kakao Brain # # 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. """Supports efficiency with skip connections.""" from .namespace import Namespace from .ski...
pytorch-master
torch/distributed/pipeline/sync/skip/__init__.py
# Copyright 2019 Kakao Brain # # 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. """Tracks skip tensors on a thread.""" from contextlib import contextmanager import threadi...
pytorch-master
torch/distributed/pipeline/sync/skip/tracker.py
# Copyright 2019 Kakao Brain # # 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. """Provides isolated namespace of skip tensors.""" import abc from functools import total_o...
pytorch-master
torch/distributed/pipeline/sync/skip/namespace.py
# -*- coding: utf-8 -*- # Copyright 2019 Kakao Brain # # 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. """The user interface to define skip connections.""" from typing im...
pytorch-master
torch/distributed/pipeline/sync/skip/skippable.py
# Copyright 2019 Kakao Brain # # 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. """Per-layer profilers.""" import copy import time from typing import Any, Generator, List,...
pytorch-master
torch/distributed/pipeline/sync/_balance/profile.py
# Copyright 2019 Kakao Brain # # 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. """A helper to roughly balance a sequential module. Usage:: import torch from tor...
pytorch-master
torch/distributed/pipeline/sync/_balance/__init__.py
# -*- coding: utf-8 -*- # Copyright 2019 Kakao Brain # # 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. """Implements "Block Partitions of Sequences" by Imre BΓ‘rΓ‘ny et al....
pytorch-master
torch/distributed/pipeline/sync/_balance/blockpartition.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...
pytorch-master
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. import sys import uuid from dataclasses import dataclass, field from typing import Any, Ca...
pytorch-master
torch/distributed/launcher/api.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.sharded_tensor import * # noqa: F403 warnings.warn( "torch.distributed._sharded_tensor will be deprecated, use to...
pytorch-master
torch/distributed/_sharded_tensor/__init__.py
import torch if torch.distributed.rpc.is_available(): from .api.remote_module import RemoteModule from .functional import * # noqa: F403
pytorch-master
torch/distributed/nn/__init__.py
import torch import torch.distributed as dist from torch.autograd import Function # 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 import group, ReduceOp def broadcast(tensor, src, g...
pytorch-master
torch/distributed/nn/functional.py
#!/usr/bin/python3 import importlib import logging import os import sys import tempfile from typing import Optional import torch from torch.distributed.nn.jit.templates.remote_module_template import ( get_remote_module_template, ) logger = logging.getLogger(__name__) _FILE_PREFIX = "_remote_module_" _TEMP_DIR ...
pytorch-master
torch/distributed/nn/jit/instantiator.py
pytorch-master
torch/distributed/nn/jit/__init__.py
pytorch-master
torch/distributed/nn/jit/templates/__init__.py
#!/usr/bin/python3 def get_remote_module_template(enable_moving_cpu_tensors_to_cuda: bool): return _TEMPLATE_PREFIX + ( _REMOTE_FORWARD_TEMPLATE_ENABLE_MOVING_CPU_TENSORS_TO_CUDA if enable_moving_cpu_tensors_to_cuda else _REMOTE_FORWARD_TEMPLATE ) _TEMPLATE_PREFIX = """from typing im...
pytorch-master
torch/distributed/nn/jit/templates/remote_module_template.py
#!/usr/bin/python3 import collections import io import sys import types from typing import ( Any, Callable, Dict, Iterator, List, Mapping, Optional, Set, Tuple, Type, TypeVar, Union, ) import torch import torch.distributed.rpc as rpc from torch import Tensor, device, dty...
pytorch-master
torch/distributed/nn/api/remote_module.py
pytorch-master
torch/distributed/nn/api/__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. """ Torchelastic agent and user worker failover contract: **TL;DR;**: * TE(torchelasti...
pytorch-master
torch/distributed/elastic/__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. """Metrics API **Overview**: The metrics API in torchelastic is used to publish telemet...
pytorch-master
torch/distributed/elastic/metrics/__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. import abc import time import warnings from collections import namedtuple from functools ...
pytorch-master
torch/distributed/elastic/metrics/api.py
# 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 datetime import random import time from base64 import b64decode, b64encode from typing import Optional im...
pytorch-master
torch/distributed/elastic/rendezvous/etcd_store.py
# 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 .api import RendezvousHandler, RendezvousParameters from .api import rendezvous_handler_registry as handler_...
pytorch-master
torch/distributed/elastic/rendezvous/registry.py
# 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. """ In the context of Torch Distributed Elastic we use the term *rendezvous* to refer to a particular functionali...
pytorch-master
torch/distributed/elastic/rendezvous/__init__.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # 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 json import logging import sys import threading import tim...
pytorch-master
torch/distributed/elastic/rendezvous/etcd_rendezvous.py
# 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 binascii import logging import os import tempfile from base64 import b64decode, b64encode from datetime im...
pytorch-master
torch/distributed/elastic/rendezvous/c10d_rendezvous_backend.py
# 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 abc import ABC, abstractmethod from typing import Any, Callable, Dict, Optional, Tuple from torch.distribut...
pytorch-master
torch/distributed/elastic/rendezvous/api.py
# 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 binascii from base64 import b64decode, b64encode from typing import Optional, Tuple, cast import urllib3....
pytorch-master
torch/distributed/elastic/rendezvous/etcd_rendezvous_backend.py
# 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 ipaddress import random import re import socket import time import weakref from datetime import timedelta ...
pytorch-master
torch/distributed/elastic/rendezvous/utils.py
# 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 inspect import logging import os import pickle import socket import threading import time import weakref f...
pytorch-master
torch/distributed/elastic/rendezvous/dynamic_rendezvous.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 atexit import logging import os import shlex import shutil import socket import sub...
pytorch-master
torch/distributed/elastic/rendezvous/etcd_server.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # 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 datetime import logging from typing import Tuple, cast, Op...
pytorch-master
torch/distributed/elastic/rendezvous/static_tcp_rendezvous.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 logging import os import time from concurrent.futures._base import Future from con...
pytorch-master
torch/distributed/elastic/multiprocessing/tail_log.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. """ Library that launches and manages ``n`` copies of worker subprocesses either specifie...
pytorch-master
torch/distributed/elastic/multiprocessing/__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. import abc import logging import os import re import signal import subprocess import sys ...
pytorch-master
torch/distributed/elastic/multiprocessing/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. # Taken and modified from original source: # https://eli.thegreenplace.net/2015/redirect...
pytorch-master
torch/distributed/elastic/multiprocessing/redirects.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. # Multiprocessing error-reporting module from torch.distributed.elastic.multiprocessing....
pytorch-master
torch/distributed/elastic/multiprocessing/errors/handlers.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. """ Each host in a distributed PyTorch job runs with a single TorchElastic agent, and mul...
pytorch-master
torch/distributed/elastic/multiprocessing/errors/__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. import faulthandler import json import logging import os import time import traceback impo...
pytorch-master
torch/distributed/elastic/multiprocessing/errors/error_handler.py
# 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 logging import multiprocessing as mp import os import signal import time from queue import Empty from typin...
pytorch-master
torch/distributed/elastic/timer/local_timer.py
# 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. """ Expiration timers are set up on the same process as the agent and used from your script to deal with stuck wo...
pytorch-master
torch/distributed/elastic/timer/__init__.py
# 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 abc import logging import threading import time from contextlib import contextmanager from inspect import g...
pytorch-master
torch/distributed/elastic/timer/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. from datetime import timedelta from typing import List def get_all(store, rank: int, pr...
pytorch-master
torch/distributed/elastic/utils/store.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 inspect import logging import os import warnings from typing import Optional from...
pytorch-master
torch/distributed/elastic/utils/logging.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 .api import get_env_variable_or_raise, get_socket_with_port, macros # noqa: F401
pytorch-master
torch/distributed/elastic/utils/__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. def get_log_level() -> str: """ Return default log level for pytorch. """ ...
pytorch-master
torch/distributed/elastic/utils/log_level.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 os import socket from string import Template from typing import List, Any def ge...
pytorch-master
torch/distributed/elastic/utils/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 datetime import socket from contextlib import closing import torch.distributed as ...
pytorch-master
torch/distributed/elastic/utils/distributed.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 math import torch from torch.utils.data.distributed import DistributedSampler c...
pytorch-master
torch/distributed/elastic/utils/data/elastic_distributed_sampler.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. class CyclingIterator: """ An iterator decorator that cycles through the und...
pytorch-master
torch/distributed/elastic/utils/data/cycling_iterator.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 .cycling_iterator import CyclingIterator # noqa: F401 from .elastic_distributed_sam...
pytorch-master
torch/distributed/elastic/utils/data/__init__.py
pytorch-master
torch/distributed/elastic/agent/__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. """ The elastic agent is the control plane of torchelastic. It is a process that launches...
pytorch-master
torch/distributed/elastic/agent/server/__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. import abc import functools import json import os import signal import socket import time...
pytorch-master
torch/distributed/elastic/agent/server/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 os import shutil import signal import tempfile from typing import Any, Dict, Opti...
pytorch-master
torch/distributed/elastic/agent/server/local_elastic_agent.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 logging from typing import Dict _log_handlers: Dict[str, logging.Handler] = { ...
pytorch-master
torch/distributed/elastic/events/handlers.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. """ Module contains events processing mechanisms that are integrated with the standard py...
pytorch-master
torch/distributed/elastic/events/__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. import json from dataclasses import asdict, dataclass, field from enum import Enum from t...
pytorch-master
torch/distributed/elastic/events/api.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...
pytorch-master
torch/distributed/autograd/__init__.py
from .join import Join from .join import Joinable from .join import JoinHook
pytorch-master
torch/distributed/algorithms/__init__.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...
pytorch-master
torch/distributed/algorithms/join.py
from . import default_hooks as default LOW_PRECISION_HOOKS = [ default.fp16_compress_hook, default.bf16_compress_hook, ]
pytorch-master
torch/distributed/algorithms/_comm_hooks/__init__.py
import functools import torch import torch.distributed as dist from torch.distributed import distributed_c10d class DefaultState(object): r""" Stores state needed to perform the default ``all_reduce`` algorithm within a communication hook. Args: process_group (ProcessGroup): The process group...
pytorch-master
torch/distributed/algorithms/_comm_hooks/default_hooks.py
from enum import Enum, auto from contextlib import suppress import torch from torch.autograd.graph import save_on_cpu from torch.utils.checkpoint import checkpoint from torch.distributed.utils import _replace_by_prefix import torch.nn as nn from typing import Any, Dict, Iterator, Tuple from functools import partial _...
pytorch-master
torch/distributed/algorithms/_checkpoint/checkpoint_wrapper.py
pytorch-master
torch/distributed/algorithms/_checkpoint/__init__.py
pytorch-master
torch/distributed/algorithms/model_averaging/__init__.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 ...
pytorch-master
torch/distributed/algorithms/model_averaging/averagers.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...
pytorch-master
torch/distributed/algorithms/model_averaging/utils.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...
pytorch-master
torch/distributed/algorithms/model_averaging/hierarchical_model_averager.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) ...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/quantization_hooks.py
from typing import Any, Callable import torch import torch.distributed as dist _FUNCTIONAL_OPTIM_STEP_METHOD_NAME = "step_param" class _OptimizerHookState(object): """ Holds state for running optimizer in-line after DDP communication hook. Currently contains only optimizer class which must have a method ...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/optimizer_overlap_hooks.py
import logging import torch import torch.distributed as dist from . import default_hooks as default logger = logging.getLogger(__name__) class PostLocalSGDState(object): r""" Stores the state for all-reducing gradients globally using ``process_group`` until step ``start_localSGD_iter``, and all-reducin...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/post_localSGD_hook.py
from enum import Enum from functools import partial import torch.distributed as dist from torch.nn.parallel import DistributedDataParallel from . import ( debugging_hooks as debugging, default_hooks as default, powerSGD_hook as powerSGD, quantization_hooks as quantization, optimizer_overlap_hooks ...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/__init__.py
from typing import Any import torch from torch.distributed import GradBucket 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 communication overheads. This ...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/debugging_hooks.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 ( _get_global_rank, _OverlapStatus, ) from torch.nn.parallel.distributed import...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/ddp_zero_hook.py
from typing import Any, Callable import torch import torch.distributed as dist def _allreduce_fut( process_group: dist.ProcessGroup, tensor: torch.Tensor ) -> torch.futures.Future[torch.Tensor]: "Averages the input gradient tensor by allreduce and returns a future." group_to_use = process_group if proces...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/default_hooks.py
from collections import defaultdict import logging import math from typing import Dict import numpy as np 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" ] lo...
pytorch-master
torch/distributed/algorithms/ddp_comm_hooks/powerSGD_hook.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....
pytorch-master
torch/distributed/algorithms/_optimizer_overlap/optimizer_overlap.py
from .optimizer_overlap import _as_overlapped_optim
pytorch-master
torch/distributed/algorithms/_optimizer_overlap/__init__.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...
pytorch-master
torch/distributed/algorithms/_quantization/quantization.py
pytorch-master
torch/distributed/algorithms/_quantization/__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 ...
pytorch-master
torch/distributed/optim/__init__.py
from typing import List, Optional, Dict 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 ...
pytorch-master
torch/distributed/optim/functional_sgd.py
from typing import List, Dict, 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, #...
pytorch-master
torch/distributed/optim/functional_adagrad.py
from typing import List, Dict, 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...
pytorch-master
torch/distributed/optim/functional_adamw.py
from typing import List, Dict, 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...
pytorch-master
torch/distributed/optim/functional_adam.py
from typing import Type from torch import optim from .functional_adagrad import _FunctionalAdagrad from .functional_adam import _FunctionalAdam from .functional_adamw import _FunctionalAdamW from .functional_sgd import _FunctionalSGD from .functional_adadelta import _FunctionalAdadelta from .functional_rmsprop import _...
pytorch-master
torch/distributed/optim/utils.py
from typing import List, Dict, 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...
pytorch-master
torch/distributed/optim/functional_rprop.py
import torch import torch.distributed.algorithms.model_averaging.averagers as averagers import warnings 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 optimi...
pytorch-master
torch/distributed/optim/post_localSGD_optimizer.py
from typing import List, Optional import logging import torch 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 RRef from .utils import functional_optim_map import torch.distributed.autograd as dist_autograd from collections i...
pytorch-master
torch/distributed/optim/optimizer.py
from typing import List, Dict, 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, ...
pytorch-master
torch/distributed/optim/functional_adadelta.py
from typing import List, Dict, 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, #...
pytorch-master
torch/distributed/optim/functional_rmsprop.py