new tasks, devnet topup, cli, new model support
This commit is contained in:
@@ -159,6 +159,30 @@ CURATED_MODELS: list[ModelPreset] = [
|
||||
]
|
||||
|
||||
|
||||
def layers_from_config(cfg) -> int | None:
|
||||
"""Extract the transformer layer count from a HuggingFace config object.
|
||||
|
||||
Composite configs (vision-language, some MoE) nest the decoder settings in
|
||||
``text_config`` — e.g. Qwen3.5-MoE has no top-level ``num_hidden_layers``.
|
||||
"""
|
||||
candidates = [cfg]
|
||||
get_text_config = getattr(cfg, "get_text_config", None)
|
||||
if callable(get_text_config):
|
||||
try:
|
||||
candidates.append(get_text_config())
|
||||
except Exception:
|
||||
pass
|
||||
nested = getattr(cfg, "text_config", None)
|
||||
if nested is not None:
|
||||
candidates.append(nested)
|
||||
for candidate in candidates:
|
||||
for attr in ("num_hidden_layers", "num_layers", "n_layer", "n_layers"):
|
||||
value = getattr(candidate, attr, None)
|
||||
if value is not None:
|
||||
return int(value)
|
||||
return None
|
||||
|
||||
|
||||
def detect_num_layers(hf_repo: str) -> int | None:
|
||||
"""Return num_hidden_layers from HuggingFace config.json (downloads ~1 KB only)."""
|
||||
# Check curated list first (no network call)
|
||||
@@ -168,7 +192,7 @@ def detect_num_layers(hf_repo: str) -> int | None:
|
||||
try:
|
||||
from transformers import AutoConfig # type: ignore[import]
|
||||
cfg = AutoConfig.from_pretrained(hf_repo)
|
||||
return int(cfg.num_hidden_layers)
|
||||
return layers_from_config(cfg)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
@@ -195,6 +219,8 @@ def model_metadata_for(
|
||||
hf_repo,
|
||||
cache_dir=str(cache_dir) if cache_dir is not None else None,
|
||||
)
|
||||
# Composite configs (VLM/MoE) nest decoder fields in text_config.
|
||||
text_cfg = getattr(cfg, "text_config", None) or cfg
|
||||
for attr, key in (
|
||||
("model_type", "architecture"),
|
||||
("num_hidden_layers", "num_layers"),
|
||||
@@ -204,8 +230,14 @@ def model_metadata_for(
|
||||
("max_position_embeddings", "context_length"),
|
||||
):
|
||||
value = getattr(cfg, attr, None)
|
||||
if value is None:
|
||||
value = getattr(text_cfg, attr, None)
|
||||
if value is not None:
|
||||
metadata[key] = value
|
||||
if "num_layers" not in metadata:
|
||||
layers = layers_from_config(cfg)
|
||||
if layers is not None:
|
||||
metadata["num_layers"] = layers
|
||||
except Exception:
|
||||
pass
|
||||
return metadata
|
||||
|
||||
Reference in New Issue
Block a user