mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-06 19:13:55 +01:00
(cherry picked from commit 4caf45b04a8faa55f191b22c069f58714236689b) Ported for #244 (part 1/6). Internal-only content from the archived commit was dropped: .aiwg records, internal runner-policy routing, and the internal security-docs test. Marked experimental in user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
3.6 KiB
Python
113 lines
3.6 KiB
Python
"""Closed registry for explicitly qualified distributed model adapters."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from types import MappingProxyType
|
|
from typing import Mapping
|
|
|
|
from obliteratus.distributed.contracts import ContractError, contract_digest
|
|
|
|
|
|
LLAMA_NATIVE_TP_PLAN: tuple[tuple[str, str], ...] = (
|
|
("lm_head", "colwise_gather_output"),
|
|
("model.layers.*.self_attn.q_proj", "colwise"),
|
|
("model.layers.*.self_attn.k_proj", "colwise"),
|
|
("model.layers.*.self_attn.v_proj", "colwise"),
|
|
("model.layers.*.self_attn.o_proj", "rowwise"),
|
|
("model.layers.*.mlp.gate_proj", "colwise"),
|
|
("model.layers.*.mlp.up_proj", "colwise"),
|
|
("model.layers.*.mlp.down_proj", "rowwise"),
|
|
)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ModelAdapterProfile:
|
|
"""Exact upstream and artifact envelope for one native-TP adapter."""
|
|
|
|
adapter_id: str
|
|
model_type: str
|
|
model_class: str
|
|
config_class: str
|
|
dtype: str
|
|
artifact_type: str
|
|
tp_size: int
|
|
torch_versions: tuple[str, ...]
|
|
transformers_versions: tuple[str, ...]
|
|
accelerate_versions: tuple[str, ...]
|
|
safetensors_versions: tuple[str, ...]
|
|
plan: tuple[tuple[str, str], ...]
|
|
runtime_storage_kind: str
|
|
|
|
@property
|
|
def plan_dict(self) -> dict[str, str]:
|
|
"""Return a fresh plan because upstream mutates distributed config objects."""
|
|
return dict(self.plan)
|
|
|
|
@property
|
|
def plan_digest(self) -> str:
|
|
return contract_digest(self.plan_dict)
|
|
|
|
@property
|
|
def digest(self) -> str:
|
|
return contract_digest(
|
|
{
|
|
"adapter_id": self.adapter_id,
|
|
"model_type": self.model_type,
|
|
"model_class": self.model_class,
|
|
"config_class": self.config_class,
|
|
"dtype": self.dtype,
|
|
"artifact_type": self.artifact_type,
|
|
"tp_size": self.tp_size,
|
|
"torch_versions": self.torch_versions,
|
|
"transformers_versions": self.transformers_versions,
|
|
"accelerate_versions": self.accelerate_versions,
|
|
"safetensors_versions": self.safetensors_versions,
|
|
"plan": self.plan_dict,
|
|
"runtime_storage_kind": self.runtime_storage_kind,
|
|
}
|
|
)
|
|
|
|
|
|
LLAMA_BF16_TP2_PROFILE = ModelAdapterProfile(
|
|
adapter_id="llama-for-causal-lm-bf16-native-tp2-v1",
|
|
model_type="llama",
|
|
model_class="LlamaForCausalLM",
|
|
config_class="LlamaConfig",
|
|
dtype="bfloat16",
|
|
artifact_type="hf_safetensors",
|
|
tp_size=2,
|
|
torch_versions=("2.13.0",),
|
|
transformers_versions=("5.15.0",),
|
|
accelerate_versions=("1.14.0",),
|
|
safetensors_versions=("0.8.0",),
|
|
plan=LLAMA_NATIVE_TP_PLAN,
|
|
runtime_storage_kind="local_tensor_parameter",
|
|
)
|
|
|
|
# Aliases keep call sites descriptive without creating another supported profile.
|
|
LLAMA_BF16_TP2_ADAPTER = LLAMA_BF16_TP2_PROFILE
|
|
MODEL_ADAPTER_REGISTRY: Mapping[str, ModelAdapterProfile] = MappingProxyType(
|
|
{LLAMA_BF16_TP2_PROFILE.adapter_id: LLAMA_BF16_TP2_PROFILE}
|
|
)
|
|
|
|
|
|
def get_model_adapter(adapter_id: str) -> ModelAdapterProfile:
|
|
"""Resolve only an exact registered adapter; compatible-looking IDs do not fall back."""
|
|
if not isinstance(adapter_id, str):
|
|
raise ContractError("model adapter id must be text")
|
|
try:
|
|
return MODEL_ADAPTER_REGISTRY[adapter_id]
|
|
except KeyError as exc:
|
|
raise ContractError("distributed model adapter is not registered") from exc
|
|
|
|
|
|
__all__ = [
|
|
"LLAMA_BF16_TP2_ADAPTER",
|
|
"LLAMA_BF16_TP2_PROFILE",
|
|
"LLAMA_NATIVE_TP_PLAN",
|
|
"MODEL_ADAPTER_REGISTRY",
|
|
"ModelAdapterProfile",
|
|
"get_model_adapter",
|
|
]
|