id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
8,962
import itertools from typing import List, Tuple import torch import torch._prims_common as utils The provided code snippet includes necessary dependencies for implementing the `fill_defaults` function. Write a Python function `def fill_defaults(args, n, defaults_tail)` to solve the following problem: __torch_dispatch_...
__torch_dispatch__ doesn't guarantee the number of arguments you are passed (e.g., defaulted arguments are not passed); but usually it is convenient to pad out the arguments list with defaults. This function helps you do that. Args: args: the list of positional arguments passed to __torch_dispatch__ n: the number of ar...
8,963
import itertools from typing import List, Tuple import torch import torch._prims_common as utils def find_arg_of_type(it, t): for x in it: if isinstance(x, t): return x return None
null
8,964
import copy from collections import OrderedDict from dataclasses import dataclass, field from typing import ( Any, cast, Dict, Iterator, List, Mapping, Optional, Set, Tuple, Type, Union, ) import torch from torch import nn, Tensor from torch.nn.modules.module import _Incompat...
null
8,965
import copy from collections import OrderedDict from dataclasses import dataclass, field from typing import ( Any, cast, Dict, Iterator, List, Mapping, Optional, Set, Tuple, Type, Union, ) import torch from torch import nn, Tensor from torch.nn.modules.module import _Incompat...
null
8,966
import copy from collections import OrderedDict from dataclasses import dataclass, field from typing import ( Any, cast, Dict, Iterator, List, Mapping, Optional, Set, Tuple, Type, Union, ) import torch from torch import nn, Tensor from torch.nn.modules.module import _Incompat...
null
8,967
import copy from collections import OrderedDict from dataclasses import dataclass, field from typing import ( Any, cast, Dict, Iterator, List, Mapping, Optional, Set, Tuple, Type, Union, ) import torch from torch import nn, Tensor from torch.nn.modules.module import _Incompat...
null
8,968
import copy from dataclasses import dataclass from typing import Any, Dict, List, Mapping, Optional, TypeVar, Union import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch.distributed import _remote_device from torch.distributed._shard...
null
8,969
import copy from dataclasses import dataclass from typing import Any, Dict, List, Mapping, Optional, TypeVar, Union import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch.distributed import _remote_device from torch.distributed._shard...
null
8,970
import copy import logging from collections import OrderedDict from itertools import accumulate from typing import Any, Dict, List, Optional, Set, Type, TypeVar, Union import torch from fbgemm_gpu.split_embedding_configs import EmbOptimType from torch import nn from torchrec import optim as trec_optim from torchrec.dis...
Appends provided prefix to provided name.
8,971
import copy import logging from collections import OrderedDict from itertools import accumulate from typing import Any, Dict, List, Optional, Set, Type, TypeVar, Union import torch from fbgemm_gpu.split_embedding_configs import EmbOptimType from torch import nn from torchrec import optim as trec_optim from torchrec.dis...
Filters state dict for keys that start with provided name. Strips provided name from beginning of key in the resulting state dict. Args: state_dict (OrderedDict[str, torch.Tensor]): input state dict to filter. name (str): name to filter from state dict keys. Returns: OrderedDict[str, torch.Tensor]: filtered state dict.
8,972
import copy import logging from collections import OrderedDict from itertools import accumulate from typing import Any, Dict, List, Optional, Set, Type, TypeVar, Union import torch from fbgemm_gpu.split_embedding_configs import EmbOptimType from torch import nn from torchrec import optim as trec_optim from torchrec.dis...
Adds prefix to all keys in state dict, in place. Args: state_dict (Dict[str, Any]): input state dict to update. prefix (str): name to filter from state dict keys. Returns: None.
8,973
import copy import logging from collections import OrderedDict from itertools import accumulate from typing import Any, Dict, List, Optional, Set, Type, TypeVar, Union import torch from fbgemm_gpu.split_embedding_configs import EmbOptimType from torch import nn from torchrec import optim as trec_optim from torchrec.dis...
Retrieves names of top level modules that do not contain any sharded sub-modules. Args: model (torch.nn.Module): model to retrieve unsharded module names from. Returns: List[str]: list of names of modules that don't have sharded sub-modules.
8,974
import copy import logging from collections import OrderedDict from itertools import accumulate from typing import Any, Dict, List, Optional, Set, Type, TypeVar, Union import torch from fbgemm_gpu.split_embedding_configs import EmbOptimType from torch import nn from torchrec import optim as trec_optim from torchrec.dis...
null
8,975
import itertools import logging from typing import Callable, Dict, List, Optional import torch import torch.distributed as dist from torch import nn from torch.autograd.profiler import record_function from torchrec.distributed.comm_ops import ( all_gather_base_pooled, alltoall_pooled, alltoall_sequence, ...
null
8,976
import itertools import logging from typing import Callable, Dict, List, Optional import torch import torch.distributed as dist from torch import nn from torch.autograd.profiler import record_function from torchrec.distributed.comm_ops import ( all_gather_base_pooled, alltoall_pooled, alltoall_sequence, ...
Calculates relevant recat indices required to reorder AlltoAll collective. Args: local_split (int): number of features in local split. num_splits (int): number of splits (typically WORLD_SIZE). stagger (int): secondary reordering, (typically 1, but `WORLD_SIZE/LOCAL_WORLD_SIZE` for TWRW). device (Optional[torch.device]...
8,977
import abc import operator from dataclasses import dataclass from enum import Enum, unique from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Type, TypeVar, Union, ) from fbgemm_gpu.split_table_batched_embeddings_ops_common import ( BoundsC...
Format a table as a string. Parameters: table (list of lists or list of tuples): The data to be formatted as a table. headers (list of strings, optional): The column headers for the table. If not provided, the first row of the table will be used as the headers. Returns: str: A string representation of the table.
8,978
import abc import operator from dataclasses import dataclass from enum import Enum, unique from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Type, TypeVar, Union, ) from fbgemm_gpu.split_table_batched_embeddings_ops_common import ( BoundsC...
null
8,979
import abc import operator from dataclasses import dataclass from enum import Enum, unique from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Type, TypeVar, Union, ) from fbgemm_gpu.split_table_batched_embeddings_ops_common import ( BoundsC...
null
8,980
import copy from collections import defaultdict, OrderedDict from dataclasses import dataclass from typing import Any, DefaultDict, Dict, Iterator, List, Optional, Type import torch import torch.distributed as dist from torch import nn from torch.distributed._shard.sharded_tensor import Shard from torchrec.distributed....
null
8,981
from collections import defaultdict, deque from dataclasses import dataclass from typing import Any, cast, Dict, List, Optional, Tuple, Type import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch import nn from torchrec.distributed.em...
null
8,982
from collections import defaultdict, deque from dataclasses import dataclass from typing import Any, cast, Dict, List, Optional, Tuple, Type import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch import nn from torchrec.distributed.em...
null
8,983
from collections import defaultdict, deque from dataclasses import dataclass from typing import Any, cast, Dict, List, Optional, Tuple, Type import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch import nn from torchrec.distributed.em...
null
8,984
from typing import Any, Dict, Iterable, Optional import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torchrec.distributed.embedding_types import GroupedEmbeddingConfig class TBEToRegisterMixIn: def get_tbes_to_register( self,...
null
8,985
from typing import Any, Dict, Iterable, Optional import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torchrec.distributed.embedding_types import GroupedEmbeddingConfig FUSED_PARAM_REGISTER_TBE_BOOL: str = "__register_tbes_in_named_module...
null
8,986
from typing import Any, Dict, Iterable, Optional import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torchrec.distributed.embedding_types import GroupedEmbeddingConfig FUSED_PARAM_QUANT_STATE_DICT_SPLIT_SCALE_BIAS: str = ( "__registe...
null
8,987
from typing import Any, Dict, Iterable, Optional import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torchrec.distributed.embedding_types import GroupedEmbeddingConfig FUSED_PARAM_REGISTER_TBE_BOOL: str = "__register_tbes_in_named_module...
null
8,988
import logging import os from typing import List, Optional, Tuple import torch import torch.distributed as dist logger: logging.Logger = logging.getLogger(__name__) _INTRA_PG: Optional[dist.ProcessGroup] = None _CROSS_PG: Optional[dist.ProcessGroup] = None def get_local_size(world_size: Optional[int] = None) -> int: ...
Creates sub process groups (intra and cross node)
8,989
from functools import partial from typing import Any, Dict, Iterator, List, Optional, Type, Union import torch from torch import nn from torchrec.distributed.embedding_types import ( BaseEmbeddingSharder, KJTList, ShardedEmbeddingModule, ) from torchrec.distributed.embeddingbag import ( EmbeddingBagColl...
null
8,990
import copy import logging import warnings from collections import defaultdict, deque, OrderedDict from dataclasses import dataclass, field from itertools import accumulate from typing import Any, cast, Dict, List, MutableMapping, Optional, Type, Union import torch from torch import nn from torch.autograd.profiler impo...
null
8,991
import copy import logging import warnings from collections import defaultdict, deque, OrderedDict from dataclasses import dataclass, field from itertools import accumulate from typing import Any, cast, Dict, List, MutableMapping, Optional, Type, Union import torch from torch import nn from torch.autograd.profiler impo...
null
8,992
import copy import logging import warnings from collections import defaultdict, deque, OrderedDict from dataclasses import dataclass, field from itertools import accumulate from typing import Any, cast, Dict, List, MutableMapping, Optional, Type, Union import torch from torch import nn from torch.autograd.profiler impo...
null
8,993
import copy import logging import warnings from collections import defaultdict, deque, OrderedDict from dataclasses import dataclass, field from itertools import accumulate from typing import Any, cast, Dict, List, MutableMapping, Optional, Type, Union import torch from torch import nn from torch.autograd.profiler impo...
null
8,994
import copy from typing import Any, Dict, List, Optional, Type import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch import nn from torchrec.distributed.embedding_lookup import EmbeddingComputeKernel from torchrec.distributed.embeddi...
null
8,995
import copy from typing import Any, Dict, List, Optional, Type import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch import nn from torchrec.distributed.embedding_lookup import EmbeddingComputeKernel from torchrec.distributed.embeddi...
null
8,996
import copy from typing import Any, Dict, List, Optional, Type import torch from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from torch import nn from torchrec.distributed.embedding_lookup import EmbeddingComputeKernel from torchrec.distributed.embeddi...
null
8,997
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
8,998
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
8,999
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
Performs AlltoAll operation for a single pooled embedding tensor. Each process splits the input pooled embeddings tensor based on the world size, and then scatters the split list to all processes in the group. Then concatenates the received tensors from all processes in the group and returns a single output tensor. Arg...
9,000
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,001
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
Performs AlltoAll operation for sequence embeddings. Each process splits the input tensor based on the world size, and then scatters the split list to all processes in the group. Then concatenates the received tensors from all processes in the group and returns a single output tensor. NOTE: AlltoAll operator for Sequen...
9,002
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
Performs `alltoallv` operation for a list of input embeddings. Each process scatters the list to all processes in the group. Args: inputs (List[Tensor]): list of tensors to scatter, one per rank. The tensors in the list usually have different lengths. out_split (Optional[List[int]]): output split sizes (or dim_sum_per_...
9,003
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
Performs reduce-scatter operation for a pooled embeddings tensor split into world size number of chunks. The result of the reduce operation gets scattered to all processes in the group. Args: inputs (List[Tensor]): list of tensors to scatter, one per rank. group (Optional[dist.ProcessGroup]): the process group to work ...
9,004
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
Reduces then scatters a flattened pooled embeddings tensor to all processes in a group. Input tensor is of size `output_tensor_size * world_size`. Args: input (Tensor): flattened tensor to scatter. group (Optional[dist.ProcessGroup]): the process group to work on. If None, the default process group will be used. codecs...
9,005
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
All-gathers tensors from all processes in a group to form a flattened pooled embeddings tensor. Input tensor is of size `output_tensor_size / world_size`. Args: input (Tensor): tensor to gather. group (Optional[dist.ProcessGroup]): the process group to work on. If None, the default process group will be used. Returns: ...
9,006
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
Performs reduce-scatter-v operation for a pooled embeddings tensor split unevenly into world size number of chunks. The result of the reduce operation gets scattered to all processes in the group according to `input_splits`. Args: input (Tensor): tensor to scatter. input_splits (List[int]): input splits. group (Optiona...
9,007
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
Performs reduce-scatter-v operation for a 1-d pooled embeddings tensor of variable batch size per feature split unevenly into world size number of chunks. The result of the reduce operation gets scattered to all processes in the group. Args: input (Tensor): tensors to scatter, one per rank. batch_size_per_rank_per_feat...
9,008
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,009
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,010
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,011
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,012
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,013
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,014
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,015
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,016
from dataclasses import dataclass, field from typing import Any, List, Optional, Tuple, TypeVar import torch import torch.distributed as dist from torch import Tensor from torch.autograd import Function from torch.autograd.profiler import record_function from torchrec.distributed.types import Awaitable, NoWait, Quantiz...
null
9,017
import abc import copy import itertools from dataclasses import dataclass from typing import ( Any, cast, Dict, Generic, Iterator, List, Optional, Tuple, TypeVar, Union, ) import torch import torch.distributed as dist from fbgemm_gpu.split_table_batched_embeddings_ops_inference i...
null
9,018
import abc import copy import itertools from dataclasses import dataclass from typing import ( Any, cast, Dict, Generic, Iterator, List, Optional, Tuple, TypeVar, Union, ) import torch import torch.distributed as dist from fbgemm_gpu.split_table_batched_embeddings_ops_inference i...
null
9,019
from typing import Callable, Dict, List, Optional, Type, Union import torch import torch.distributed as dist from torch import nn from torch.distributed._composable.contract import contract from torchrec.distributed.comm import get_local_size from torchrec.distributed.model_parallel import get_default_sharders from tor...
Replaces all sub_modules that are embedding modules with their sharded variants. This embedding_module -> sharded_embedding_module mapping is derived from the passed in sharders. This will leave the other parts of the model unaffected. It returns the original module Args: module (nn.Module): module to wrap. env (Option...
9,020
import math import warnings from typing import Callable, cast, Dict, List, Optional, Tuple, Type import torch from torch import distributed as dist, nn from torchrec.distributed.comm import get_local_size from torchrec.distributed.embedding import EmbeddingCollectionSharder from torchrec.distributed.embedding_types imp...
Returns a generator of ParameterShardingPlan for `ShardingType::DATA_PARALLEL` for construct_module_sharding_plan. Example:: ebc = EmbeddingBagCollection(...) plan = construct_module_sharding_plan( ebc, { "table_0": data_parallel(), }, )
9,021
import math import warnings from typing import Callable, cast, Dict, List, Optional, Tuple, Type import torch from torch import distributed as dist, nn from torchrec.distributed.comm import get_local_size from torchrec.distributed.embedding import EmbeddingCollectionSharder from torchrec.distributed.embedding_types imp...
Returns a generator of ParameterShardingPlan for `ShardingType::TABLE_WISE` for construct_module_sharding_plan. Args: rank (int): rank to place table when doing table wise Example:: ebc = EmbeddingBagCollection(...) plan = construct_module_sharding_plan( ebc, { "table_0": table_wise(rank=0), }, )
9,022
import math import warnings from typing import Callable, cast, Dict, List, Optional, Tuple, Type import torch from torch import distributed as dist, nn from torchrec.distributed.comm import get_local_size from torchrec.distributed.embedding import EmbeddingCollectionSharder from torchrec.distributed.embedding_types imp...
Returns a generator of ParameterShardingPlan for `ShardingType::ROW_WISE` for construct_module_sharding_plan. Args: sizes_placement (Optional[Tuple[List[int], str]]): Only use it in inference for uneven shardinglist of tuples of (sizes, placement); sizes is the row size list Example:: ebc = EmbeddingBagCollection(...) ...
9,023
import math import warnings from typing import Callable, cast, Dict, List, Optional, Tuple, Type import torch from torch import distributed as dist, nn from torchrec.distributed.comm import get_local_size from torchrec.distributed.embedding import EmbeddingCollectionSharder from torchrec.distributed.embedding_types imp...
Returns a generator of ParameterShardingPlan for `ShardingType::COLUMN_WISE` for construct_module_sharding_plan. Table will the sharded column-wise evenly across specified ranks (and can reuse ranks). Args: ranks (List[int]): ranks to place columns Example:: ebc = EmbeddingBagCollection(...) plan = construct_module_sha...
9,024
import math import warnings from typing import Callable, cast, Dict, List, Optional, Tuple, Type import torch from torch import distributed as dist, nn from torchrec.distributed.comm import get_local_size from torchrec.distributed.embedding import EmbeddingCollectionSharder from torchrec.distributed.embedding_types imp...
Returns a generator of ParameterShardingPlan for `ShardingType::TABLE_ROW_WISE` for construct_module_sharding_plan. Args: host_index (int): index of host (node) to do row wise Example:: ebc = EmbeddingBagCollection(...) plan = construct_module_sharding_plan( ebc, { "table_4": table_row_wise(host_index=2), }, )
9,025
import math import warnings from typing import Callable, cast, Dict, List, Optional, Tuple, Type import torch from torch import distributed as dist, nn from torchrec.distributed.comm import get_local_size from torchrec.distributed.embedding import EmbeddingCollectionSharder from torchrec.distributed.embedding_types imp...
Convenience function to apply a sharding scheme generator for all modules in construct_module_sharding_plan. Example:: ebc = EmbeddingBagCollection(...) sharder = EmbeddingBagCollectionSharder() plan = construct_parameter_sharding_plan( ebc, apply_to_all(ebc, row_wise(), sharder), )
9,026
import math import warnings from typing import Callable, cast, Dict, List, Optional, Tuple, Type import torch from torch import distributed as dist, nn from torchrec.distributed.comm import get_local_size from torchrec.distributed.embedding import EmbeddingCollectionSharder from torchrec.distributed.embedding_types imp...
Helper function to create module sharding plans (EmbeddingModuleShardingPlan) for an module Args: module (nn.Module): module to create plan for. per_param_sharding: Dict[str, Callable[[nn.Parameter, int, int, str], ParameterSharding]]: A mapping of parameter names to a generator function that takes in [parameter, local...
9,027
import abc import copy from collections import OrderedDict from typing import Any, cast, Dict, Iterator, List, Optional, Set, Tuple, Type import torch import torch.distributed as dist from torch import nn from torch.distributed.algorithms.ddp_comm_hooks import ( default_hooks as ddp_default_hooks, ) from torch.dist...
Unwraps module wrapped by DMP, DDP, or FSDP.
9,028
import abc import copy from collections import OrderedDict from typing import Any, cast, Dict, Iterator, List, Optional, Set, Tuple, Type import torch import torch.distributed as dist from torch import nn from torch.distributed.algorithms.ddp_comm_hooks import ( default_hooks as ddp_default_hooks, ) from torch.dist...
Unwraps DMP module. Does not unwrap data parallel wrappers (i.e. DDP/FSDP), so overriding implementations by the wrappers can be used.
9,029
from typing import List, Tuple from torchrec.distributed.quant_embeddingbag import ShardedQuantEmbeddingBagCollection class ShardedQuantEmbeddingBagCollection( ShardedQuantEmbeddingModuleState[ ListOfKJTList, List[List[torch.Tensor]], KeyedTensor, NullShardedModuleContext, ], ):...
null
9,030
import abc import copy import uuid from collections import defaultdict from dataclasses import dataclass from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar, Union import torch from torch import distributed as dist, nn from torchrec.distributed.dist_data import ( KJTAllToAllTensorsAwaitable, S...
Bucketizes the `values` in KeyedJaggedTensor into `num_buckets` buckets, `lengths` are readjusted based on the bucketization results. Note: This function should be used only for row-wise sharding before calling `KJTAllToAll`. Args: num_buckets (int): number of buckets to bucketize the values into. block_sizes: (torch.T...
9,031
import abc import copy import uuid from collections import defaultdict from dataclasses import dataclass from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar, Union import torch from torch import distributed as dist, nn from torchrec.distributed.dist_data import ( KJTAllToAllTensorsAwaitable, S...
Groups tables by `DataType`, `PoolingType`, and `EmbeddingComputeKernel`. Args: tables_per_rank (List[List[ShardedEmbeddingTable]]): list of sharded embedding tables per rank with consistent weightedness. Returns: List[List[GroupedEmbeddingConfig]]: per rank list of GroupedEmbeddingConfig for features.
9,032
import abc import copy import uuid from collections import defaultdict from dataclasses import dataclass from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar, Union import torch from torch import distributed as dist, nn from torchrec.distributed.dist_data import ( KJTAllToAllTensorsAwaitable, S...
null
9,033
import abc import copy import uuid from collections import defaultdict from dataclasses import dataclass from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar, Union import torch from torch import distributed as dist, nn from torchrec.distributed.dist_data import ( KJTAllToAllTensorsAwaitable, S...
null
9,034
import abc import copy import uuid from collections import defaultdict from dataclasses import dataclass from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar, Union import torch from torch import distributed as dist, nn from torchrec.distributed.dist_data import ( KJTAllToAllTensorsAwaitable, S...
null
9,035
import logging from abc import ABC from collections import OrderedDict from typing import Any, cast, Dict, Iterator, List, Optional, Tuple, Union import torch import torch.distributed as dist from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from fbgemm...
null
9,036
import logging from abc import ABC from collections import OrderedDict from typing import Any, cast, Dict, Iterator, List, Optional, Tuple, Union import torch import torch.distributed as dist from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from fbgemm...
null
9,037
import logging from abc import ABC from collections import OrderedDict from typing import Any, cast, Dict, Iterator, List, Optional, Tuple, Union import torch import torch.distributed as dist from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from fbgemm...
null
9,038
import logging from abc import ABC from collections import OrderedDict from typing import Any, cast, Dict, Iterator, List, Optional, Tuple, Union import torch import torch.distributed as dist from fbgemm_gpu.split_table_batched_embeddings_ops_inference import ( IntNBitTableBatchedEmbeddingBagsCodegen, ) from fbgemm...
null
9,039
import copy import itertools import logging from collections import defaultdict from dataclasses import dataclass, field from threading import Event, Thread from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Set, Tuple, Type, TypeVar, U...
null
9,040
import copy import itertools import logging from collections import defaultdict from dataclasses import dataclass, field from threading import Event, Thread from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Set, Tuple, Type, TypeVar, U...
As mentioned in https://pytorch.org/docs/stable/generated/torch.Tensor.record_stream.html, PyTorch uses the "caching allocator" for memory allocation for tensors. When a tensor is freed, its memory is likely to be reused by newly constructed tenosrs. By default, this allocator traces whether a tensor is still in use by...
9,041
import copy import itertools import logging from collections import defaultdict from dataclasses import dataclass, field from threading import Event, Thread from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Set, Tuple, Type, TypeVar, U...
null
9,042
import copy import itertools import logging from collections import defaultdict from dataclasses import dataclass, field from threading import Event, Thread from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Set, Tuple, Type, TypeVar, U...
null
9,043
import copy import itertools import logging from collections import defaultdict from dataclasses import dataclass, field from threading import Event, Thread from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Set, Tuple, Type, TypeVar, U...
Overrides each input dist forward to support fusing the splits collective. NOTE: this can only be called after the input dists are initialized.
9,044
import copy import itertools import logging from collections import defaultdict from dataclasses import dataclass, field from threading import Event, Thread from typing import ( Any, Callable, cast, Dict, Generic, Iterator, List, Optional, Set, Tuple, Type, TypeVar, U...
null
9,045
import abc import logging from typing import cast, Generic, Iterator, List, Optional, Tuple import torch from torch.autograd.profiler import record_function from torchrec.distributed.model_parallel import ShardedModule from torchrec.distributed.train_pipeline.utils import ( _override_input_dist_forwards, _rewri...
null
9,046
from functools import wraps from typing import Any, Callable, cast, Optional, TypeVar import torch.distributed as dist The provided code snippet includes necessary dependencies for implementing the `is_leader` function. Write a Python function `def is_leader(pg: Optional[dist.ProcessGroup], leader_rank: int = 0) -> bo...
Checks if the current processs is the leader. Args: pg (Optional[dist.ProcessGroup]): the process's rank within the pg is used to determine if the process is the leader. pg being None implies that the process is the only member in the group (e.g. a single process program). leader_rank (int): the definition of leader (d...
9,047
from functools import wraps from typing import Any, Callable, cast, Optional, TypeVar import torch.distributed as dist T = TypeVar("T") def invoke_on_rank_and_broadcast_result( pg: dist.ProcessGroup, rank: int, func: Callable[..., T], *args: Any, **kwargs: Any, ) -> T: """ Invokes a function...
null
9,048
import copy import itertools import logging from decimal import Decimal from typing import cast, Dict, List, Optional, Set, Tuple, Union import torch from torchrec.distributed.embedding_types import EmbeddingComputeKernel from torchrec.distributed.planner.types import ( Enumerator, Perf, Proposer, Shard...
null
9,049
import copy import itertools import logging from decimal import Decimal from typing import cast, Dict, List, Optional, Set, Tuple, Union import torch from torchrec.distributed.embedding_types import EmbeddingComputeKernel from torchrec.distributed.planner.types import ( Enumerator, Perf, Proposer, Shard...
only works for static_feedback proposers (the path of proposals to check is independent of the performance of the proposals)
9,050
import copy import logging import math from typing import Dict, List, Optional, Set, Tuple from torch import nn from torchrec.distributed.planner.constants import BIGINT_DTYPE, POOLING_FACTOR from torchrec.distributed.planner.types import ( ParameterConstraints, PlannerError, PlannerErrorType, Storage, ...
null
9,051
import copy import logging import math from typing import Dict, List, Optional, Set, Tuple from torch import nn from torchrec.distributed.planner.constants import BIGINT_DTYPE, POOLING_FACTOR from torchrec.distributed.planner.types import ( ParameterConstraints, PlannerError, PlannerErrorType, Storage, ...
null
9,052
import copy import logging import math from typing import Dict, List, Optional, Set, Tuple from torch import nn from torchrec.distributed.planner.constants import BIGINT_DTYPE, POOLING_FACTOR from torchrec.distributed.planner.types import ( ParameterConstraints, PlannerError, PlannerErrorType, Storage, ...
null
9,053
import copy import logging import math from typing import Dict, List, Optional, Set, Tuple from torch import nn from torchrec.distributed.planner.constants import BIGINT_DTYPE, POOLING_FACTOR from torchrec.distributed.planner.types import ( ParameterConstraints, PlannerError, PlannerErrorType, Storage, ...
null
9,054
import math import operator from functools import reduce from typing import Any, cast, Dict, Iterable, List, Optional, Tuple, Type, Union import torch from torchrec.distributed.planner.types import Perf, ShardingOption, Storage from torchrec.distributed.types import ShardingType def bytes_to_mb(num_bytes: Union[float,...
null
9,055
import math import operator from functools import reduce from typing import Any, cast, Dict, Iterable, List, Optional, Tuple, Type, Union import torch from torchrec.distributed.planner.types import Perf, ShardingOption, Storage from torchrec.distributed.types import ShardingType def gb_to_bytes(gb: float) -> int: ...
null
9,056
import math import operator from functools import reduce from typing import Any, cast, Dict, Iterable, List, Optional, Tuple, Type, Union import torch from torchrec.distributed.planner.types import Perf, ShardingOption, Storage from torchrec.distributed.types import ShardingType def bytes_to_gb(num_bytes: int) -> float...
null
9,057
import math import operator from functools import reduce from typing import Any, cast, Dict, Iterable, List, Optional, Tuple, Type, Union import torch from torchrec.distributed.planner.types import Perf, ShardingOption, Storage from torchrec.distributed.types import ShardingType class ShardingOption: """ One w...
null
9,058
import math import operator from functools import reduce from typing import Any, cast, Dict, Iterable, List, Optional, Tuple, Type, Union import torch from torchrec.distributed.planner.types import Perf, ShardingOption, Storage from torchrec.distributed.types import ShardingType class Perf: """ Representation ...
Find the tables that are causing the imbalance, and return their names.
9,059
import copy from functools import reduce from time import perf_counter from typing import cast, Dict, List, Optional, Tuple, Union import torch import torch.distributed as dist from torch import nn from torchrec.distributed.collective_utils import invoke_on_rank_and_broadcast_result from torchrec.distributed.comm impor...
null
9,060
import logging from collections import defaultdict from typing import Any, cast, Dict, List, Optional, Tuple, Union from torch import nn from torchrec.distributed.planner.constants import BIGINT_DTYPE, NUM_POOLINGS from torchrec.distributed.planner.shard_estimators import _calculate_shard_io_sizes from torchrec.distrib...
null
9,061
import logging from collections import defaultdict from typing import Any, cast, Dict, List, Optional, Tuple, Union from torch import nn from torchrec.distributed.planner.constants import BIGINT_DTYPE, NUM_POOLINGS from torchrec.distributed.planner.shard_estimators import _calculate_shard_io_sizes from torchrec.distrib...
null