repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/modeling/__init__.py
colossalai/shardformer/modeling/__init__.py
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/modeling/mixtral.py
colossalai/shardformer/modeling/mixtral.py
import inspect import warnings from typing import Callable, List, Optional, Tuple, Union import torch import torch.distributed as dist import torch.nn.functional as F from torch.distributed import ProcessGroup from torch.nn import CrossEntropyLoss from transformers.cache_utils import Cache, DynamicCache from transform...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
true
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/modeling/mistral.py
colossalai/shardformer/modeling/mistral.py
import warnings from typing import List, Optional, Tuple, Union import torch from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss from transformers.cache_utils import Cache, DynamicCache from transformers.modeling_outputs import ( BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassi...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/modeling/chatglm2_6b/modeling_chatglm.py
colossalai/shardformer/modeling/chatglm2_6b/modeling_chatglm.py
""" The ChatGLM2-6B License 1. Definitions “Licensor” means the ChatGLM2-6B Model Team that distributes its Software. “Software” means the ChatGLM2-6B model parameters made available under this license. 2. License Grant Subject to the terms and conditions of this License, the Licensor hereby grants to you a non-ex...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
true
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/modeling/chatglm2_6b/configuration_chatglm.py
colossalai/shardformer/modeling/chatglm2_6b/configuration_chatglm.py
from transformers import PretrainedConfig class ChatGLMConfig(PretrainedConfig): model_type = "chatglm" def __init__( self, num_layers=28, padded_vocab_size=65024, hidden_size=4096, ffn_hidden_size=13696, kv_channels=128, num_attention_heads=32, ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/modeling/chatglm2_6b/__init__.py
colossalai/shardformer/modeling/chatglm2_6b/__init__.py
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/examples/convergence_benchmark.py
colossalai/shardformer/examples/convergence_benchmark.py
import argparse import math from typing import Any, List, Union import evaluate import torch import torch.distributed as dist from data import GLUEDataBuilder from torch import nn from torch.optim import Adam, Optimizer from torch.utils._pytree import tree_map from torch.utils.data import DataLoader from tqdm import t...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/examples/performance_benchmark.py
colossalai/shardformer/examples/performance_benchmark.py
""" Shardformer Benchmark """ import torch import torch.distributed as dist import transformers import triton import colossalai from colossalai.shardformer import ShardConfig, ShardFormer def data_gen(batch_size, seq_length): input_ids = torch.randint(0, seq_length, (batch_size, seq_length), dtype=torch.long) ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/examples/data.py
colossalai/shardformer/examples/data.py
import datasets from torch.utils.data import DataLoader from transformers import AutoTokenizer, PreTrainedTokenizer from colossalai.booster.plugin.dp_plugin_base import DPPluginBase class GLUEDataBuilder: task_text_field_map = { "cola": ["sentence"], "sst2": ["sentence"], "mrpc": ["senten...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/shard/grad_ckpt_config.py
colossalai/shardformer/shard/grad_ckpt_config.py
from dataclasses import dataclass from typing import List, Optional @dataclass class GradientCheckpointConfig: gradient_checkpointing_ratio: float = 0.0 def get_num_ckpt_layers(self, num_layers: int) -> int: return int(self.gradient_checkpointing_ratio * num_layers) @dataclass class PipelineGradien...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/shard/sharder.py
colossalai/shardformer/shard/sharder.py
from types import MethodType from typing import Any, Callable, Dict, List, Optional, Set, Union import torch.nn as nn from torch import Tensor from colossalai.lazy import LazyInitContext from .._utils import getattr_, setattr_ from ..policies.auto_policy import get_autopolicy from ..policies.base_policy import Polic...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/shard/utils.py
colossalai/shardformer/shard/utils.py
from typing import Set import torch.nn as nn def set_tensors_to_none(model: nn.Module, exclude: Set[nn.Module] = set()) -> None: """Set all parameters and buffers of model to None Args: model (nn.Module): The model to set """ if model in exclude: return for child in model.childre...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/shard/__init__.py
colossalai/shardformer/shard/__init__.py
from .grad_ckpt_config import GradientCheckpointConfig, PipelineGradientCheckpointConfig from .shard_config import ShardConfig from .sharder import ModelSharder from .shardformer import ShardFormer __all__ = ["ShardConfig", "ModelSharder", "ShardFormer", "PipelineGradientCheckpointConfig", "GradientCheckpointConfig"]
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/shard/shard_config.py
colossalai/shardformer/shard/shard_config.py
import warnings from dataclasses import dataclass, field from typing import Any, Dict, Optional import torch.distributed as dist from torch.distributed import ProcessGroup from colossalai.pipeline.stage_manager import PipelineStageManager from .grad_ckpt_config import GradientCheckpointConfig __all__ = ["ShardConfi...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/shardformer/shard/shardformer.py
colossalai/shardformer/shard/shardformer.py
from typing import Dict, List, Tuple import torch.distributed as dist import torch.nn as nn from torch import Tensor from colossalai.cluster import DistCoordinator from ..policies.base_policy import Policy from .shard_config import ShardConfig from .sharder import ModelSharder class ShardFormer: """ Parall...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/context/singleton_meta.py
colossalai/context/singleton_meta.py
import threading class SingletonMeta(type): """ Thread-safe Singleton Meta with double-checked locking. Reference: https://en.wikipedia.org/wiki/Double-checked_locking """ _instances = {} _lock = threading.Lock() def __call__(cls, *args, **kwargs): # First check (without locking)...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/context/config.py
colossalai/context/config.py
#!/usr/bin/env python # -*- encoding: utf-8 -*- import inspect import sys from importlib.machinery import SourceFileLoader from pathlib import Path from colossalai.logging import get_dist_logger class Config(dict): """This is a wrapper class for dict objects so that values of which can be accessed as attrib...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/context/__init__.py
colossalai/context/__init__.py
from .config import Config, ConfigException __all__ = [ "Config", "ConfigException", ]
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/_compatibility.py
colossalai/fx/_compatibility.py
from typing import Callable import torch TORCH_MAJOR = int(torch.__version__.split(".")[0]) TORCH_MINOR = int(torch.__version__.split(".")[1]) if TORCH_MAJOR == 1 and TORCH_MINOR < 12: META_COMPATIBILITY = False elif TORCH_MAJOR == 1 and TORCH_MINOR == 12: META_COMPATIBILITY = True elif TORCH_MAJOR == 1 and ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/_meta_regist_12.py
colossalai/fx/_meta_regist_12.py
# meta patch from https://github.com/pytorch/pytorch/blob/master/torch/_meta_registrations.py # should be activated for PyTorch version 1.12.0 and below # refer to https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/native_functions.yaml # for more meta_registrations from typing import List, Optional, ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/_meta_regist_13.py
colossalai/fx/_meta_regist_13.py
import torch from torch._meta_registrations import register_meta from torch._prims_common import check aten = torch.ops.aten # since we fix the torch version to 1.13.1, we have to add unimplemented meta ops # all these functions are from here https://github.com/pytorch/pytorch/blob/master/torch/_meta_registrations.p...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/__init__.py
colossalai/fx/__init__.py
from ._compatibility import compatibility, is_compatible_with_meta from .graph_module import ColoGraphModule from .passes import MetaInfoProp, metainfo_trace from .tracer import ColoTracer, meta_trace, symbolic_trace
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/graph_module.py
colossalai/fx/graph_module.py
import os import warnings from pathlib import Path from typing import Any, Dict, Optional, Union import torch import torch.nn as nn from torch.nn.modules.module import _addindent try: from torch.fx.graph import Graph, PythonCode, _PyTreeCodeGen from torch.fx.graph_module import GraphModule, _exec_with_source,...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/proxy.py
colossalai/fx/proxy.py
from typing import Any import torch from torch.fx.proxy import Proxy from colossalai.fx.tracer.meta_patch import meta_patched_function __all__ = ["ColoProxy"] class ColoProxy(Proxy): """ ColoProxy is a proxy class which uses meta tensor to handle data-dependent control flow. The original torch.fx proxy ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/memory_utils.py
colossalai/fx/profiler/memory_utils.py
from typing import Dict, List, Tuple, Union import torch from torch.fx import Node from .._compatibility import compatibility, is_compatible_with_meta __all__ = ["activation_size", "parameter_size", "is_inplace"] @compatibility(is_backward_compatible=True) def activation_size(out: Union[torch.Tensor, Dict, List, T...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/constants.py
colossalai/fx/profiler/constants.py
import torch __all__ = ["ALIAS_ATEN", "INPLACE_NEW", "INPLACE_MATH_ATEN", "CLONE_ATEN", "RELU_LIKE_OPS", "RELU_LIKE_MOD"] aten = torch.ops.aten ALIAS_ATEN = [ aten.detach.default, aten.t.default, aten.transpose.int, aten.view.default, aten._unsafe_view.default, aten._reshape_alias.default, ] ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/profiler.py
colossalai/fx/profiler/profiler.py
import time from functools import partial from typing import Any, Callable, Dict, Tuple import torch from torch.fx import Graph, Node from torch.fx.node import Argument, Target from torch.nn.parameter import Parameter from torch.utils._pytree import tree_map from .._compatibility import compatibility from .constants ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/opcount.py
colossalai/fx/profiler/opcount.py
# adopted from https://github.com/facebookresearch/fvcore/blob/main/fvcore/nn/jit_handles.py # ideas from https://pastebin.com/AkvAyJBw import operator from functools import partial, reduce from numbers import Number from typing import Any, Callable, List import torch from packaging import version aten = torch.ops.a...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/dataflow.py
colossalai/fx/profiler/dataflow.py
from dataclasses import dataclass, field from enum import Enum from typing import Dict, List from torch.fx import Graph, Node from .._compatibility import compatibility from .memory_utils import activation_size, is_inplace class Phase(Enum): FORWARD = 0 BACKWARD = 1 PLACEHOLDER = 2 @compatibility(is_b...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/__init__.py
colossalai/fx/profiler/__init__.py
from .._compatibility import is_compatible_with_meta if is_compatible_with_meta(): from .opcount import flop_mapping from .profiler import profile_function, profile_method, profile_module from .shard_utils import ( calculate_bwd_time, calculate_fwd_in, calculate_fwd_out, cal...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/tensor.py
colossalai/fx/profiler/tensor.py
import uuid import torch from torch.types import _device from torch.utils._pytree import tree_map from .._compatibility import compatibility from .constants import ALIAS_ATEN __all__ = ["MetaTensor"] def set_data_ptr(x): if isinstance(x, torch.Tensor): if not x.data_ptr(): data_ptr = uuid.u...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/shard_utils.py
colossalai/fx/profiler/shard_utils.py
import torch from torch.fx import Node from .._compatibility import compatibility, is_compatible_with_meta from .memory_utils import activation_size if is_compatible_with_meta(): from .constants import OUTPUT_SAVED_MOD, OUTPUT_SAVED_OPS __all__ = ["calculate_fwd_in", "calculate_fwd_tmp", "calculate_fwd_out"] @...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/registry.py
colossalai/fx/profiler/experimental/registry.py
class ProfilerRegistry: def __init__(self, name): self.name = name self.store = {} def register(self, source): def wrapper(func): self.store[source] = func return func return wrapper def get(self, source): assert source in self.store ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/constants.py
colossalai/fx/profiler/experimental/constants.py
from operator import add, floordiv, getitem, mul, neg, pos, setitem, sub import torch __all__ = ["INPLACE_OPS", "INPLACE_METHOD", "NON_INPLACE_METHOD"] # TODO fill out the inplace ops INPLACE_OPS = [ add, sub, mul, floordiv, neg, pos, getitem, setitem, getattr, torch.Tensor.cp...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler.py
colossalai/fx/profiler/experimental/profiler.py
from dataclasses import dataclass from typing import Any, Callable, Dict, Tuple import torch from torch.fx.node import Argument, Target from ..._compatibility import compatibility from ..memory_utils import activation_size from .constants import INPLACE_METHOD, INPLACE_OPS, NON_INPLACE_METHOD from .registry import me...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/__init__.py
colossalai/fx/profiler/experimental/__init__.py
from .profiler import profile_function, profile_method, profile_module from .profiler_function import * from .profiler_module import * from .registry import meta_profiler_function, meta_profiler_module from .shard_utils import calculate_fwd_in, calculate_fwd_out, calculate_fwd_tmp
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/shard_utils.py
colossalai/fx/profiler/experimental/shard_utils.py
# for PyTorch 1.11 compatibility uses from torch.fx import Node from ..._compatibility import compatibility __all__ = ["calculate_fwd_in", "calculate_fwd_tmp", "calculate_fwd_out"] @compatibility(is_backward_compatible=True) def calculate_fwd_in(n: Node) -> bool: """A helper function to calculate `fwd_in` ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/torch_ops.py
colossalai/fx/profiler/experimental/profiler_function/torch_ops.py
import operator from functools import reduce from typing import Any, Optional, Tuple import torch from ..registry import meta_profiler_function @meta_profiler_function.register(torch.arange) @meta_profiler_function.register(torch.finfo) @meta_profiler_function.register(torch.permute) @meta_profiler_function.registe...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/arithmetic.py
colossalai/fx/profiler/experimental/profiler_function/arithmetic.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import operator from functools import reduce from typing import Any, Optional, Tuple, Union import torch from ..registry import meta_profiler_function def _elementwise_flops_compute(input, other): # copied from https://github.com/microsof...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/pooling.py
colossalai/fx/profiler/experimental/profiler_function/pooling.py
from typing import Tuple import torch from ..registry import meta_profiler_function @meta_profiler_function.register(torch.nn.functional.avg_pool1d) @meta_profiler_function.register(torch.nn.functional.avg_pool2d) @meta_profiler_function.register(torch.nn.functional.avg_pool3d) @meta_profiler_function.register(torc...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/activation_function.py
colossalai/fx/profiler/experimental/profiler_function/activation_function.py
from typing import Tuple import torch from ..registry import meta_profiler_function # TODO: different activation has different FLOPs count, currently unused. _multiplier = { torch.nn.functional.relu: 1, torch.nn.functional.prelu: 4, torch.nn.functional.sigmoid: 4, torch.nn.functional.tanh: 5, tor...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/python_ops.py
colossalai/fx/profiler/experimental/profiler_function/python_ops.py
import operator from typing import Any, Tuple from ..registry import meta_profiler_function @meta_profiler_function.register(operator.getitem) def operator_getitem(a: Any, b: Any) -> Tuple[int, int]: flops = 0 macs = 0 return flops, macs @meta_profiler_function.register(getattr) def python_getattr(a: A...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/__init__.py
colossalai/fx/profiler/experimental/profiler_function/__init__.py
from .activation_function import * from .arithmetic import * from .embedding import * from .linear import * from .normalization import * from .pooling import * from .python_ops import * from .torch_ops import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/embedding.py
colossalai/fx/profiler/experimental/profiler_function/embedding.py
from typing import Optional import torch from ..registry import meta_profiler_function @meta_profiler_function.register(torch.nn.functional.embedding) def torch_nn_functional_embedding( input: torch.Tensor, weight: torch.Tensor, padding_idx: Optional[int] = None, max_norm: Optional[float] = None, ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/normalization.py
colossalai/fx/profiler/experimental/profiler_function/normalization.py
from typing import List, Optional, Tuple import torch from ..registry import meta_profiler_function @meta_profiler_function.register(torch.nn.functional.instance_norm) def torch_nn_func_instancenorm( input: torch.Tensor, running_mean: Optional[torch.Tensor] = None, running_var: Optional[torch.Tensor] = ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_function/linear.py
colossalai/fx/profiler/experimental/profiler_function/linear.py
from typing import Tuple import torch from ..registry import meta_profiler_function @meta_profiler_function.register(torch.nn.functional.linear) def torch_nn_linear(input: torch.Tensor, weight: torch.Tensor, bias: torch.Tensor = None) -> Tuple[int, int]: out_features = weight.shape[0] macs = torch.numel(inp...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/convolution.py
colossalai/fx/profiler/experimental/profiler_module/convolution.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import math import operator from functools import reduce from typing import Tuple import torch from ..registry import meta_profiler_module @meta_profiler_module.register(torch.nn.Conv1d) def torch_nn_conv1d(self: torch.nn.Conv1d, input: torch...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/pooling.py
colossalai/fx/profiler/experimental/profiler_module/pooling.py
from typing import Tuple import torch from ..registry import meta_profiler_module @meta_profiler_module.register(torch.nn.AvgPool1d) @meta_profiler_module.register(torch.nn.AvgPool2d) @meta_profiler_module.register(torch.nn.AvgPool3d) @meta_profiler_module.register(torch.nn.MaxPool1d) @meta_profiler_module.register...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/torch_op.py
colossalai/fx/profiler/experimental/profiler_module/torch_op.py
from typing import Tuple import torch from ..registry import meta_profiler_module @meta_profiler_module.register(torch.nn.Flatten) def torch_nn_flatten(self: torch.nn.Flatten, input: torch.Tensor) -> Tuple[int, int]: flops = 0 macs = 0 return flops, macs
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/rnn.py
colossalai/fx/profiler/experimental/profiler_module/rnn.py
import operator from functools import reduce from typing import Optional, Tuple import torch from ..registry import meta_profiler_module def _rnn_flops( flops: int, macs: int, module: torch.nn.RNNBase, w_ih: torch.Tensor, w_hh: torch.Tensor ) -> Tuple[int, int]: # copied from https://github.com/sovrasov/flo...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/dropout.py
colossalai/fx/profiler/experimental/profiler_module/dropout.py
from typing import Tuple import torch from ..registry import meta_profiler_module @meta_profiler_module.register(torch.nn.Dropout) def torch_nn_dropout(self: torch.nn.Module, input: torch.Tensor) -> Tuple[int, int]: # nn.Embedding is a dictionary lookup, so technically it has 0 FLOPs. (https://discuss.pytorch.o...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/activation_function.py
colossalai/fx/profiler/experimental/profiler_module/activation_function.py
from typing import Tuple import torch from ..registry import meta_profiler_module # TODO: different activation has different FLOPs count, currently unused. _multiplier = { torch.nn.ReLU: 1, torch.nn.PReLU: 4, torch.nn.Sigmoid: 4, torch.nn.Tanh: 5, torch.nn.LeakyReLU: 3, torch.nn.ELU: 4, t...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/__init__.py
colossalai/fx/profiler/experimental/profiler_module/__init__.py
from .activation_function import * from .attention import * from .convolution import * from .dropout import * from .embedding import * from .linear import * from .normalization import * from .pooling import * from .rnn import * from .torch_op import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/attention.py
colossalai/fx/profiler/experimental/profiler_module/attention.py
from typing import Optional, Tuple import torch from ..registry import meta_profiler_module # TODO: This is hard to compute memory cost @meta_profiler_module.register(torch.nn.MultiheadAttention) def torch_nn_msa( self: torch.nn.MultiheadAttention, query: torch.Tensor, key: torch.Tensor, value: torc...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/embedding.py
colossalai/fx/profiler/experimental/profiler_module/embedding.py
from typing import Tuple import torch from ..registry import meta_profiler_module @meta_profiler_module.register(torch.nn.Embedding) def torch_nn_embedding(self: torch.nn.Embedding, input: torch.Tensor) -> Tuple[int, int]: # nn.Embedding is a dictionary lookup, so technically it has 0 FLOPs. (https://discuss.py...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/normalization.py
colossalai/fx/profiler/experimental/profiler_module/normalization.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from typing import Tuple, Union import torch from ..registry import meta_profiler_module @meta_profiler_module.register(torch.nn.InstanceNorm1d) @meta_profiler_module.register(torch.nn.InstanceNorm2d) @meta_profiler_module.register(torch.nn.I...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/profiler/experimental/profiler_module/linear.py
colossalai/fx/profiler/experimental/profiler_module/linear.py
from typing import Tuple import torch from ..registry import meta_profiler_module @meta_profiler_module.register(torch.nn.Linear) @meta_profiler_module.register(torch.nn.modules.linear.NonDynamicallyQuantizableLinear) def torch_nn_linear(self: torch.nn.Linear, input: torch.Tensor) -> Tuple[int, int]: out_featur...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/_symbolic_trace.py
colossalai/fx/tracer/_symbolic_trace.py
from typing import Any, Callable, Dict, Optional, Union import torch from colossalai.fx import ColoGraphModule from colossalai.fx._compatibility import compatibility from .tracer import ColoTracer @compatibility(is_backward_compatible=True) def symbolic_trace( root: Union[torch.nn.Module, Callable[..., Any]], ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/registry.py
colossalai/fx/tracer/registry.py
class PatchRegistry: def __init__(self, name): self.name = name self.store = {} def register(self, source): def wrapper(func): self.store[source] = func return func return wrapper def get(self, source): assert source in self.store ta...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/tracer.py
colossalai/fx/tracer/tracer.py
#!/usr/bin/env python """ tracer.py: Implemented a tracer which supports control flow and user-defined meta arguments. The implementation is partly inspired HuggingFace's fx tracer """ import enum import functools import inspect import operator from contextlib import contextmanager from typing import Any, Dict,...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/_meta_trace.py
colossalai/fx/tracer/_meta_trace.py
import torch from torch.fx import Graph, Node from torch.utils._pytree import tree_map def normalize_tuple(x): if not isinstance(x, tuple): return (x,) return x def is_autogradable(x): return isinstance(x, torch.Tensor) and x.is_floating_point() def meta_trace(module: torch.nn.Module, fake_dev...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/_tracer_utils.py
colossalai/fx/tracer/_tracer_utils.py
from typing import Any, List, Union import torch from ..proxy import ColoProxy from .meta_patch import meta_patched_function __all__ = ["is_element_in_list", "extract_meta"] def is_element_in_list(elements: Union[List[Any], Any], list_: List[Any]): if isinstance(elements, (tuple, list, set)): for ele i...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/__init__.py
colossalai/fx/tracer/__init__.py
from colossalai.fx.tracer.meta_patch.patched_function.python_ops import operator_getitem from ._meta_trace import meta_trace from ._symbolic_trace import symbolic_trace from .tracer import ColoTracer
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/experimental.py
colossalai/fx/tracer/experimental.py
import functools import inspect import operator from contextlib import contextmanager from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union import torch from torch.fx import Graph, Node, Proxy, Tracer from torch.utils._pytree import tree_map from colossalai.fx import ColoGraphModule, compatibility...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/__init__.py
colossalai/fx/tracer/meta_patch/__init__.py
from .patched_function import * from .patched_module import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/convolution.py
colossalai/fx/tracer/meta_patch/patched_function/convolution.py
import collections import math from itertools import repeat import torch from ...registry import meta_patched_function def _ntuple(n, name="parse"): def parse(x): if isinstance(x, collections.abc.Iterable): return tuple(x) return tuple(repeat(x, n)) parse.__name__ = name ret...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/torch_ops.py
colossalai/fx/tracer/meta_patch/patched_function/torch_ops.py
import torch from ...registry import meta_patched_function @meta_patched_function.register(torch.arange) def torch_arange(*args, **kwargs): n = len(args) step = 1 if n == 1: start = 0 end = args[0] elif n == 2: start, end = args else: start, end, step = args if...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/arithmetic.py
colossalai/fx/tracer/meta_patch/patched_function/arithmetic.py
import torch from ...registry import meta_patched_function @meta_patched_function.register(torch.matmul) @meta_patched_function.register("matmul") # for built-in op @ def torch_matmul(input, other, *, out=None): # copied from huggingface.utils.fx d1 = input.dim() d2 = other.dim() shape = None if...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/activation_function.py
colossalai/fx/tracer/meta_patch/patched_function/activation_function.py
import torch from ...registry import meta_patched_function @meta_patched_function.register(torch.nn.functional.relu) def torch_nn_func_relu(input, inplace=False): return torch.empty(input.shape, device="meta")
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/python_ops.py
colossalai/fx/tracer/meta_patch/patched_function/python_ops.py
import operator import torch from colossalai.fx.proxy import ColoProxy from ...registry import meta_patched_function @meta_patched_function.register(operator.getitem) def operator_getitem(a, b): # copied from huggingface.utils.fx def to_concrete(t): if isinstance(t, torch.Tensor): concr...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/__init__.py
colossalai/fx/tracer/meta_patch/patched_function/__init__.py
from .activation_function import * from .arithmetic import * from .convolution import * from .embedding import * from .normalization import * from .torch_ops import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/embedding.py
colossalai/fx/tracer/meta_patch/patched_function/embedding.py
import torch from ...registry import meta_patched_function @meta_patched_function.register(torch.nn.functional.embedding) def torch_nn_functional_embedding( input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False ): return torch.empty(*input.shape, weight.shape[-...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_function/normalization.py
colossalai/fx/tracer/meta_patch/patched_function/normalization.py
import torch from ...registry import meta_patched_function @meta_patched_function.register(torch.nn.functional.layer_norm) def torch_nn_func_layernorm(input, normalized_shape, weight=None, bias=None, eps=1e-05): return torch.empty(input.shape, device="meta") @meta_patched_function.register(torch.nn.functional....
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/convolution.py
colossalai/fx/tracer/meta_patch/patched_module/convolution.py
import math import torch from ...registry import meta_patched_module @meta_patched_module.register(torch.nn.Conv1d) def torch_nn_conv1d(self, input): # the output shape is calculated using the formula stated # at https://pytorch.org/docs/stable/generated/torch.nn.Conv1d.html#torch.nn.Conv1d l_in = input...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/pooling.py
colossalai/fx/tracer/meta_patch/patched_module/pooling.py
import math import torch from ...registry import meta_patched_module @meta_patched_module.register(torch.nn.AvgPool1d) def torch_nn_avgpool1d(self, input): num_dim = input.dim() assert num_dim in [2, 3], f"expected the input to have 2 or 3 dimensions, but got {num_dim} dimensions" l_in = input.shape[-1...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/rnn.py
colossalai/fx/tracer/meta_patch/patched_module/rnn.py
import torch from ...registry import meta_patched_module @meta_patched_module.register(torch.nn.GRU) @meta_patched_module.register(torch.nn.RNN) def torch_nn_rnn(self, input, hx): assert ( input.shape[-1] == self.input_size ), f"Expected input to have input size {self.input_size} but got {input.shape...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/activation_function.py
colossalai/fx/tracer/meta_patch/patched_module/activation_function.py
import torch from ...registry import meta_patched_module @meta_patched_module.register(torch.nn.ReLU) @meta_patched_module.register(torch.nn.Sigmoid) @meta_patched_module.register(torch.nn.GELU) @meta_patched_module.register(torch.nn.Tanh) @meta_patched_module.register(torch.nn.ReLU6) @meta_patched_module.register(t...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/__init__.py
colossalai/fx/tracer/meta_patch/patched_module/__init__.py
from .activation_function import * from .convolution import * from .embedding import * from .linear import * from .normalization import * from .pooling import * from .rnn import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/embedding.py
colossalai/fx/tracer/meta_patch/patched_module/embedding.py
import torch from ...registry import meta_patched_module @meta_patched_module.register(torch.nn.Embedding) def torch_nn_embedding(self, input): result_shape = input.shape + (self.embedding_dim,) return torch.empty(result_shape, device="meta")
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/normalization.py
colossalai/fx/tracer/meta_patch/patched_module/normalization.py
import torch from ...registry import meta_patched_module @meta_patched_module.register(torch.nn.LayerNorm) @meta_patched_module.register(torch.nn.GroupNorm) @meta_patched_module.register(torch.nn.BatchNorm1d) @meta_patched_module.register(torch.nn.BatchNorm2d) @meta_patched_module.register(torch.nn.BatchNorm3d) def ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/meta_patch/patched_module/linear.py
colossalai/fx/tracer/meta_patch/patched_module/linear.py
import torch from ...registry import meta_patched_module @meta_patched_module.register(torch.nn.Linear) def torch_nn_linear(self, input): last_dim = input.shape[-1] assert ( last_dim == self.in_features ), f"Expected hidden size {self.in_features} but got {last_dim} for the torch.nn.Linear patch"...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/__init__.py
colossalai/fx/tracer/bias_addition_patch/__init__.py
from .patched_bias_addition_function import * from .patched_bias_addition_module import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/conv.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/conv.py
import torch from torch.nn.modules.utils import _pair, _single, _triple from ...registry import bias_addition_module from .bias_addition_module import BiasAdditionModule @bias_addition_module.register(torch.nn.Conv1d) @bias_addition_module.register(torch.nn.Conv2d) @bias_addition_module.register(torch.nn.Conv3d) cla...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/bias_addition_module.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/bias_addition_module.py
import operator from abc import ABC, abstractmethod import torch import torch.nn.functional as F class BiasAdditionModule(ABC): """ This class is used to construct the restructure computation graph for call_module node with bias addition inside. """ def __init__(self, tracer, target, args, kwarg...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/__init__.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/__init__.py
from .bias_addition_module import * from .conv import * from .linear import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/linear.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_module/linear.py
import torch from ...registry import bias_addition_module from .bias_addition_module import BiasAdditionModule @bias_addition_module.register(torch.nn.Linear) class BiasAdditionLinear(BiasAdditionModule): def extract_kwargs_from_mod(self): return {} def generate(self): non_bias_linear_func_p...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/addbmm.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/addbmm.py
import torch from ...registry import bias_addition_function, bias_addition_method from .bias_addition_function import LinearBasedBiasFunc @bias_addition_method.register(torch.Tensor.addbmm) @bias_addition_function.register(torch.addbmm) class Addbmm(LinearBasedBiasFunc): def extract_kwargs_from_origin_func(self)...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/addmm.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/addmm.py
import torch from ...registry import bias_addition_function, bias_addition_method from .bias_addition_function import LinearBasedBiasFunc @bias_addition_method.register(torch.Tensor.addmm) @bias_addition_function.register(torch.addmm) class Addmm(LinearBasedBiasFunc): def extract_kwargs_from_origin_func(self): ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/bias_addition_function.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/bias_addition_function.py
import operator from abc import ABC, abstractmethod import torch import torch.nn.functional as F class BiasAdditionFunc(ABC): """ This class is used to construct the restructure computation graph for call_func node with bias addition inside. """ def __init__(self, tracer, target, args, kwargs, s...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/__init__.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/__init__.py
from .addbmm import Addbmm from .addmm import Addmm from .bias_addition_function import BiasAdditionFunc, LinearBasedBiasFunc, func_to_func_dict, method_to_func_dict from .linear import Linear
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/linear.py
colossalai/fx/tracer/bias_addition_patch/patched_bias_addition_function/linear.py
import torch.nn.functional as F from ...registry import bias_addition_function from .bias_addition_function import LinearBasedBiasFunc @bias_addition_function.register(F.linear) class Linear(LinearBasedBiasFunc): def extract_kwargs_from_origin_func(self): assert "bias" in self.kwargs kwargs = {} ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/codegen/activation_checkpoint_codegen.py
colossalai/fx/codegen/activation_checkpoint_codegen.py
from typing import Any, Dict, Iterable, List, Tuple import torch import colossalai try: from torch.fx.graph import ( CodeGen, PythonCode, _custom_builtins, _CustomBuiltin, _format_target, _is_from_torch, _Namespace, _origin_type_map, inplace...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
true
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/codegen/__init__.py
colossalai/fx/codegen/__init__.py
from .activation_checkpoint_codegen import *
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/passes/shard_1d_pass.py
colossalai/fx/passes/shard_1d_pass.py
import operator import torch import torch.nn as nn from colossalai.legacy.tensor import ProcessGroup from colossalai.legacy.tensor.compute_spec import ComputePattern, ComputeSpec from colossalai.legacy.tensor.distspec import ShardSpec ELEMENTWISE_MODULE_OP = [torch.nn.Dropout, torch.nn.ReLU] ELEMENTWISE_FUNC_OP = [ ...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/passes/adding_split_node_pass.py
colossalai/fx/passes/adding_split_node_pass.py
import numpy as np import torch import tqdm from colossalai.fx.passes.split_module import split_module def pipe_split(): pass def block_split(): pass # Construct blocks with the condition that (block_flops / total_flops) >= limit. def construct_blocks(gm: torch.fx.GraphModule, limit=0.01): total_fwd_...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/passes/utils.py
colossalai/fx/passes/utils.py
from typing import Dict import torch from torch.fx.graph import Graph from torch.fx.node import Node, map_arg def get_comm_size(prev_partition, next_partition): """ Given two partitions (parent and child), calculate the communication size between the two. """ # Keep tracking the communication siz...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/passes/meta_info_prop.py
colossalai/fx/passes/meta_info_prop.py
from dataclasses import asdict from typing import Any, Dict, List, NamedTuple, Tuple import torch import torch.fx from torch.fx.node import Argument, Node, Target from torch.utils._pytree import tree_map from colossalai.fx._compatibility import compatibility, is_compatible_with_meta from colossalai.fx.profiler import...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/passes/concrete_info_prop.py
colossalai/fx/passes/concrete_info_prop.py
from dataclasses import asdict from typing import Any, Dict, List, Optional, Tuple import torch import torch.fx from torch.fx.node import Argument, Node, Target from torch.utils._pytree import tree_flatten from colossalai.fx._compatibility import compatibility from colossalai.fx.profiler import GraphInfo, profile_fun...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/passes/__init__.py
colossalai/fx/passes/__init__.py
from .adding_split_node_pass import balanced_split_pass, split_with_split_nodes_pass from .concrete_info_prop import ConcreteInfoProp from .meta_info_prop import MetaInfoProp, metainfo_trace from .shard_1d_pass import column_shard_linear_pass, row_shard_linear_pass
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false
hpcaitech/ColossalAI
https://github.com/hpcaitech/ColossalAI/blob/b1915d2889543949eb5b610241f1515c73df5059/colossalai/fx/passes/split_module.py
colossalai/fx/passes/split_module.py
import inspect from typing import Any, Callable, Dict, List, Optional import torch from packaging import version from torch.fx._compatibility import compatibility from torch.fx.graph_module import GraphModule @compatibility(is_backward_compatible=True) class Partition: """ Adapted from https://github.com/pyt...
python
Apache-2.0
b1915d2889543949eb5b610241f1515c73df5059
2026-01-04T14:40:19.002665Z
false