from __future__ import annotations
import logging
logger = logging.getLogger("modelexpress.transfer_safety")
def detect_model_features(model_config) -> dict[str, str]:
hf_config = (
getattr(model_config, "hf_text_config", None)
or getattr(model_config, "pretrained_config", None)
)
features: dict[str, str] = {}
features["model_type"] = getattr(hf_config, "model_type", "unknown")
dtype = getattr(model_config, "dtype", None)
if dtype is None:
dtype = getattr(model_config, "torch_dtype", None)
features["dtype"] = str(dtype).replace("torch.", "")
quantization = getattr(model_config, "quantization", None)
if quantization is None:
quant_config = getattr(model_config, "quant_config", None)
quantization = getattr(quant_config, "quant_algo", None)
features["quantization"] = str(quantization or "none")
kv_lora_rank = getattr(hf_config, "kv_lora_rank", None)
has_mla = isinstance(kv_lora_rank, int)
features["attention"] = "mla" if has_mla else "standard"
num_experts = (
getattr(hf_config, "n_routed_experts", None)
or getattr(hf_config, "num_local_experts", None)
)
if isinstance(num_experts, int) and num_experts > 1:
features["moe"] = str(num_experts)
return features
def check_transfer_allowed(model_config) -> tuple[bool, str]:
features = detect_model_features(model_config)
logger.info(f"[Transfer Safety] P2P transfer allowed. Features: {features}")
return True, "allowed"