Track Kimi model metadata and cache path
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -15,6 +16,7 @@ class ModelPreset:
|
||||
vram_int8: float
|
||||
vram_bf16: float
|
||||
description: str
|
||||
metadata: dict | None = None
|
||||
|
||||
def vram_for_quant(self, quant: str) -> float:
|
||||
"""Return VRAM requirement in GB for the given quantization."""
|
||||
@@ -123,6 +125,37 @@ CURATED_MODELS: list[ModelPreset] = [
|
||||
vram_bf16=16.0,
|
||||
description="DeepSeek's efficient MoE — strong coding + reasoning",
|
||||
),
|
||||
ModelPreset(
|
||||
name="Kimi-K2.7-Code",
|
||||
hf_repo="unsloth/Kimi-K2.7-Code",
|
||||
num_layers=61,
|
||||
vram_nf4=500.0,
|
||||
vram_int8=1000.0,
|
||||
vram_bf16=2000.0,
|
||||
description="Moonshot/Unsloth coding-focused MoE model; 1T total, 32B activated",
|
||||
metadata={
|
||||
"architecture": "Mixture-of-Experts (MoE)",
|
||||
"total_parameters": "1T",
|
||||
"activated_parameters": "32B",
|
||||
"num_layers": 61,
|
||||
"dense_layers": 1,
|
||||
"attention_hidden_dimension": 7168,
|
||||
"moe_hidden_dimension_per_expert": 2048,
|
||||
"attention_heads": 64,
|
||||
"experts": 384,
|
||||
"selected_experts_per_token": 8,
|
||||
"shared_experts": 1,
|
||||
"vocabulary_size": 160000,
|
||||
"context_length": 256000,
|
||||
"attention_mechanism": "MLA",
|
||||
"activation_function": "SwiGLU",
|
||||
"vision_encoder": "MoonViT",
|
||||
"vision_encoder_parameters": "400M",
|
||||
"license": "modified-mit",
|
||||
"native_quantization": "int4",
|
||||
"recommended_engines": ["vLLM", "SGLang", "KTransformers"],
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -140,6 +173,44 @@ def detect_num_layers(hf_repo: str) -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
def model_metadata_for(
|
||||
hf_repo: str,
|
||||
num_layers: int | None = None,
|
||||
cache_dir: Path | None = None,
|
||||
) -> dict:
|
||||
"""Return operator-facing model metadata for a HuggingFace repo."""
|
||||
for model in CURATED_MODELS:
|
||||
if model.hf_repo == hf_repo:
|
||||
metadata = dict(model.metadata or {})
|
||||
metadata.setdefault("num_layers", model.num_layers)
|
||||
return metadata
|
||||
|
||||
metadata: dict = {}
|
||||
if num_layers is not None:
|
||||
metadata["num_layers"] = num_layers
|
||||
try:
|
||||
from transformers import AutoConfig # type: ignore[import]
|
||||
|
||||
cfg = AutoConfig.from_pretrained(
|
||||
hf_repo,
|
||||
cache_dir=str(cache_dir) if cache_dir is not None else None,
|
||||
)
|
||||
for attr, key in (
|
||||
("model_type", "architecture"),
|
||||
("num_hidden_layers", "num_layers"),
|
||||
("hidden_size", "hidden_size"),
|
||||
("num_attention_heads", "attention_heads"),
|
||||
("vocab_size", "vocabulary_size"),
|
||||
("max_position_embeddings", "context_length"),
|
||||
):
|
||||
value = getattr(cfg, attr, None)
|
||||
if value is not None:
|
||||
metadata[key] = value
|
||||
except Exception:
|
||||
pass
|
||||
return metadata
|
||||
|
||||
|
||||
def browse_hf_hub(top_n: int = 20) -> list[dict]:
|
||||
"""Fetch top downloaded text-generation models from HuggingFace Hub."""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user