| AutoTPMeta |
Ran ran on a synthesized input · constructed an object; no result was computed |
deepspeedai/DeepSpeed/deepspeed/sequence/layer.py code served (permissive licence) · get_code("4346fff083939110") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned AutoTPMeta: the class was constructed and called, and the call returned an instance of its own class. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
from dataclasses import dataclass
from typing import Optional
_ATTN_HEAD_ATTRS = ('num_attention_heads', 'num_heads', 'n_heads', 'n_head', 'attention_heads')
_KV_HEAD_ATTRS = ('num_key_value_heads', 'num_kv_heads', 'multi_query_group_num', 'n_head_kv', 'kv_n_heads', 'num_attention_heads', 'n_heads', 'attention_heads')
def _attention_head_count_from(config) -> Optional[int]:
"""First non-None attention head count found on ``config`` via :data:`_ATTN_HEAD_ATTRS`, else ``None``."""
for name in _ATTN_HEAD_ATTRS:
value = getattr(config, name, None)
if value is not None:
return value
return None
def _kv_head_count_from(config) -> Optional[int]:
"""First non-None kv-head count found on ``config`` via :data:`_KV_HEAD_ATTRS`, else ``None``."""
for name in _KV_HEAD_ATTRS:
value = getattr(config, name, None)
if value is not None:
return value
return None
@dataclass(frozen=True)
class AutoTPMeta:
"""Per-model tensor-parallel metadata AutoTP derives from the model config.
Each model carries its own kv-head / grain values so its layers, fused-QKV repacking and
checkpoint conversion shard consistently, and more than one AutoTP model can live in the
same process.
"""
num_kv_heads: Optional[int] = None
num_attention_heads: Optional[int] = None
n_embd: Optional[int] = None
tp_grain_size: int = 1
@classmethod
def from_model_config(cls, model_config, tp_grain_size: int=1) -> 'AutoTPMeta':
"""The single source of truth for reading kv-head / hidden / attention-head counts.
``model_config`` may be ``None`` for callers that build a synthetic AutoTP with no real
model (some unit tests); they get an empty meta and the resulting even-grain split.
"""
if model_config is None:
return cls(tp_grain_size=tp_grain_size)
text_config = getattr(model_config, 'text_config', None)
if text_config is not None:
model_config = text_config
num_kv_heads = _kv_head_count_from(model_config)
n_embd = None
for name in ('n_embd', 'hidden_size'):
if hasattr(model_config, name):
n_embd = getattr(model_config, name)
if n_embd is not None:
break
num_attention_heads = _attention_head_count_from(model_config)
return cls(num_kv_heads=num_kv_heads, num_attention_heads=num_attention_heads, n_embd=n_embd, tp_grain_size=tp_grain_size)
class MockConfig:
def __init__(self, num_attention_heads=8, num_kv_heads=2, hidden_size=256):
self.num_attention_heads = num_attention_heads
self.num_kv_heads = num_kv_heads
self.hidden_size = hidden_size
INIT_ARGS = {
'num_kv_heads': None,
'num_attention_heads': None,
'n_embd': None,
'tp_grain_size': 1,
}
ARGS = {
'model_config': MockConfig(num_attention_heads=8, num_kv_heads=2, hidden_size=256),
'tp_grain_size': 2,
}
METHOD = 'from_model_config'
if __name__ == '__main__':
instance = AutoTPMeta(**INIT_ARGS)
print(f"Instance created: {instance}")
result = instance.from_model_config(**ARGS)
print(f"Method result: {result}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type AutoTPMeta — the call returned an instance of its own class, which has no array shape; none is stated — the instrument coerces any output to an array; for a AutoTPMeta output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| _attention_head_count_from |
Ran ran, honoured the contract we drafted |
deepspeedai/DeepSpeed/deepspeed/sequence/layer.py code served (permissive licence) · get_code("6838070708760fe4") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
# Create a minimal config class with attention head count attribute
class MinimalConfig:
def __init__(self, num_attention_heads=8):
self.num_attention_heads = num_attention_heads
# Test case 1: config with num_attention_heads attribute
config_with_heads = MinimalConfig(num_attention_heads=12)
ARGS = {
'config': config_with_heads
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| _kv_head_count_from |
Ran ran, honoured the contract we drafted |
deepspeedai/DeepSpeed/deepspeed/sequence/layer.py code served (permissive licence) · get_code("1fd65563e4f7ec38") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import numpy as np
class MockConfig:
"""Stand-in config object for testing _kv_head_count_from"""
def __init__(self, num_key_value_heads=None, num_kv_heads=None,
multi_query_group_num=None, n_head_kv=None, kv_n_heads=None,
num_attention_heads=None, n_heads=None, attention_heads=None):
self.num_key_value_heads = num_key_value_heads
self.num_kv_heads = num_kv_heads
self.multi_query_group_num = multi_query_group_num
self.n_head_kv = n_head_kv
self.kv_n_heads = kv_n_heads
self.num_attention_heads = num_attention_heads
self.n_heads = n_heads
self.attention_heads = attention_heads
# Test case 1: config with num_key_value_heads set
config_with_kv_heads = MockConfig(num_key_value_heads=8)
ARGS = {
"config": config_with_kv_heads
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| get_shard_size |
Ran ran, honoured the contract we drafted |
deepspeedai/DeepSpeed/deepspeed/sequence/layer.py code served (permissive licence) · get_code("52ac3e38db39cd2f") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import numpy as np
from dataclasses import dataclass
from typing import Optional
# Define AutoTPMeta since it's used in the function
@dataclass(frozen=True)
class AutoTPMeta:
"""Per-model tensor-parallel metadata AutoTP derives from the model config."""
num_kv_heads: Optional[int] = None
num_attention_heads: Optional[int] = None
n_embd: Optional[int] = None
tp_grain_size: int = 1
# Create a mock dist module with necessary functions
class MockDist:
def __init__(self):
self._rank = 0
self._world_size = 2
def get_rank(self, group=None):
return self._rank
def get_world_size(self, group=None):
return self._world_size
# Set up the global dist
import types as _types
dist = MockDist()
# Now define ARGS with all required parameters for get_shard_size
ARGS = {
'total_size': 256,
'mp_size': 2,
'meta': AutoTPMeta(num_kv_heads=8, num_attention_heads=32, n_embd=512, tp_grain_size=64),
'name': 'attention_layer',
'rank': 0,
'mp_group': None,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| get_shard_size_list |
Ran ran, honoured the contract we drafted |
deepspeedai/DeepSpeed/deepspeed/sequence/layer.py code served (permissive licence) · get_code("349bb5104a5aa798") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
from dataclasses import dataclass
from typing import Optional
torch.manual_seed(0)
@dataclass(frozen=True)
class AutoTPMeta:
num_kv_heads: Optional[int] = None
num_attention_heads: Optional[int] = None
n_embd: Optional[int] = None
tp_grain_size: int = 1
@classmethod
def from_model_config(cls, model_config, tp_grain_size: int=1) -> 'AutoTPMeta':
if model_config is None:
return cls(tp_grain_size=tp_grain_size)
text_config = getattr(model_config, 'text_config', None)
if text_config is not None:
model_config = text_config
num_kv_heads = _kv_head_count_from(model_config)
n_embd = None
for name in ('n_embd', 'hidden_size'):
if hasattr(model_config, name):
n_embd = getattr(model_config, name)
if n_embd is not None:
break
num_attention_heads = _attention_head_count_from(model_config)
return cls(num_kv_heads=num_kv_heads, num_attention_heads=num_attention_heads, n_embd=n_embd, tp_grain_size=tp_grain_size)
_ATTN_HEAD_ATTRS = ('num_attention_heads', 'num_heads', 'n_heads', 'n_head', 'attention_heads')
_KV_HEAD_ATTRS = ('num_key_value_heads', 'num_kv_heads', 'multi_query_group_num', 'n_head_kv', 'kv_n_heads', 'num_attention_heads', 'n_heads', 'attention_heads')
def _attention_head_count_from(config) -> Optional[int]:
for name in _ATTN_HEAD_ATTRS:
value = getattr(config, name, None)
if value is not None:
return value
return None
def _kv_head_count_from(config) -> Optional[int]:
for name in _KV_HEAD_ATTRS:
value = getattr(config, name, None)
if value is not None:
return value
return None
def get_shard_size(total_size, mp_size, meta: AutoTPMeta, name=None, rank=None, mp_group=None):
num_kv_heads = meta.num_kv_heads
tp_grain_size = meta.tp_grain_size
last_linear = ['lm_head', 'embed_out']
moe_mlp_layer = ['gate_proj', 'up_proj', 'down_proj', 'w1', 'w2', 'w3']
not_moe_mlp_layer = True
if name != None and any((s in str(name) for s in moe_mlp_layer)):
not_moe_mlp_layer = False
if rank is None:
rank = 0
if num_kv_heads is not None and total_size % num_kv_heads == 0 and ('mlp' not in str(name)) and (str(name) not in last_linear) and not_moe_mlp_layer:
my_slices = num_kv_heads // mp_size + (1 if rank < num_kv_heads % mp_size else 0)
return total_size * my_slices // num_kv_heads
elif total_size >= tp_grain_size:
grain_size, remainder = divmod(total_size, tp_grain_size)
shard_size = (grain_size // mp_size + (1 if rank < grain_size % mp_size else 0)) * tp_grain_size
if rank == mp_size - 1:
shard_size += remainder
return shard_size
else:
return total_size // mp_size + (1 if rank < total_size % mp_size else 0)
def get_shard_size_list(total_size, mp_size, meta: AutoTPMeta, name=None):
shard_sizes = []
for i in range(mp_size):
shard_sizes.append(get_shard_size(total_size, mp_size, meta, name, i))
assert sum(shard_sizes) == total_size, f"AutoTP shard sizes {shard_sizes} for layer '{name}' do not sum to the dimension size {total_size} with tp_size={mp_size}, tp_grain_size={meta.tp_grain_size}"
return shard_sizes
meta = AutoTPMeta(num_kv_heads=8, num_attention_heads=32, n_embd=256, tp_grain_size=64)
ARGS = {
'total_size': 512,
'mp_size': 4,
'meta': meta,
'name': 'attention_layer'
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type list, ndim 1, dtype family int — a list output has no array shape of its own; none is stated
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| uneven_heads_all2all |
Not yet run unverified (harvested, no recorded run) |
deepspeedai/DeepSpeed/deepspeed/sequence/layer.py code served (permissive licence) · get_code("556e5b0b420e135d") How it ran |