Run 35B MoE models in ~2.5 GB of RAM. Weights stream from SSD; a trained router predicts loads a step ahead. Mac, iPhone, Android, Windows supported
Python
test: add real checkpoint smoke coverage
chuarunyuan13c320db77be
diff --git a/README.md b/README.mdindex 3bf4e46..4aabb62 100644--- a/README.md+++ b/README.md@@ -253,8 +253,11 @@ python examples/bench.py edge0-8b # via $EDGE0_8B_MODEL```bashpytest # unit tests (no real weights)-pytest -m slow # end-to-end with real checkpoints (generation + HTTP)-scripts/e2e_smoke.py # staged vs exact numerical consistency smoke+EDGE0_8B_MODEL=/path/to/edge0-8b pytest -m slow -q+ # real-weight generation; missing tiers are skipped+.venv/bin/python scripts/e2e_smoke.py \+ --qwen-dir /path/to/edge0-35b --ling-dir /path/to/edge0-8b+ # staged vs exact consistency + generation smokescripts/generate_example.py # full-pipeline API exampleexamples/demo.py # minimal API walkthrough```diff --git a/README_zh.md b/README_zh.mdindex 8805853..14e03c4 100644--- a/README_zh.md+++ b/README_zh.md@@ -214,8 +214,11 @@ python examples/bench.py edge0-8b # 经 $EDGE0_8B_MODEL```bashpytest # 单元测试(不含真实权重)-pytest -m slow # 真实 checkpoint 端到端(qwen/ling 生成 + HTTP)-scripts/e2e_smoke.py # 两档模型 staged vs exact 数值一致性冒烟+EDGE0_8B_MODEL=/path/to/edge0-8b pytest -m slow -q+ # 真实权重生成测试;缺少的档位会明确 skip+.venv/bin/python scripts/e2e_smoke.py \+ --qwen-dir /path/to/edge0-35b --ling-dir /path/to/edge0-8b+ # staged vs exact 一致性 + 生成冒烟scripts/generate_example.py # 完整 API 上手例子(prefill→生成→解码全链路)examples/demo.py # 最小 API walkthrough(edge0 demo 的等价代码)```diff --git a/scripts/e2e_smoke.py b/scripts/e2e_smoke.pyindex 1052a85..2a87490 100644--- a/scripts/e2e_smoke.py+++ b/scripts/e2e_smoke.py@@ -12,6 +12,7 @@ Usage:from __future__ import annotationsimport argparse+import osimport sysimport time@@ -24,6 +25,13 @@ QWEN_DEFAULT = os.environ.get("EDGE0_35B_MODEL", "/path/to/qwen35/model")LING_DEFAULT = os.environ.get("EDGE0_8B_MODEL", "/path/to/ling/model")+def _available(label: str, model_dir: str) -> bool:+ if os.path.isdir(model_dir):+ return True+ print(f"[skip] {label} checkpoint not found: {model_dir}")+ return False++def _prompt_ids(model_dir: str, text: str) -> list[int]:tok = io.load_tokenizer(model_dir)return list(tok(text)["input_ids"])@@ -57,24 +65,33 @@ def main() -> int:ap.add_argument("--max-new", type=int, default=16)args = ap.parse_args()- qwen_prompt = _prompt_ids(args.qwen_dir, "Hello!")- ling_prompt = _prompt_ids(args.ling_dir, "你好")-- staged = run("edge0-35b", args.qwen_dir, qwen_prompt, args.max_new,- label="[staged]")- exact = run("edge0-35b", args.qwen_dir, qwen_prompt, args.max_new,- options=LayerOptions(staged=False, staged_replace=False,- full_layer_prefill=False,- hot_per_layer=0, use_compile=False,- history_prefetch=False),- label="[exact]")- if staged != exact:- print("MISMATCH: staged vs exact greedy sequences differ "- f"(staged={staged} exact={exact})")+ ran = False+ if _available("edge0-35b", args.qwen_dir):+ qwen_prompt = _prompt_ids(args.qwen_dir, "Hello!")+ staged = run("edge0-35b", args.qwen_dir, qwen_prompt, args.max_new,+ label="[staged]")+ exact = run("edge0-35b", args.qwen_dir, qwen_prompt, args.max_new,+ options=LayerOptions(staged=False, staged_replace=False,+ full_layer_prefill=False,+ hot_per_layer=0, use_compile=False,+ history_prefetch=False),+ label="[exact]")+ if staged != exact:+ print("MISMATCH: staged vs exact greedy sequences differ "+ f"(staged={staged} exact={exact})")+ return 1+ print("qwen staged == exact greedy: OK")+ ran = True++ if _available("edge0-8b", args.ling_dir):+ ling_prompt = _prompt_ids(args.ling_dir, "你好")+ run("edge0-8b", args.ling_dir, ling_prompt, args.max_new,+ label="[staged]")+ ran = True++ if not ran:+ print("edge0 e2e smoke: no checkpoints available", file=sys.stderr)return 1- print("qwen staged == exact greedy: OK")-- run("edge0-8b", args.ling_dir, ling_prompt, args.max_new, label="[staged]")print("edge0 e2e smoke OK")return 0diff --git a/tests/test_e2e_slow.py b/tests/test_e2e_slow.pynew file mode 100644index 0000000..3e4d8b7--- /dev/null+++ b/tests/test_e2e_slow.py@@ -0,0 +1,89 @@+"""Real-checkpoint smoke tests for the shipped model tiers.++Set ``EDGE0_8B_MODEL`` and/or ``EDGE0_35B_MODEL`` to checkpoint directories+before running ``pytest -m slow``. A missing tier is an explicit skip so a+machine without every large checkpoint can still exercise the available one.+"""++from __future__ import annotations++import os+import time+from pathlib import Path++import pytest++from edge0 import AutoEngine+from edge0.config import GenerationConfig+++pytestmark = pytest.mark.slow++MAX_NEW_TOKENS = 8+++def _checkpoint(env_name: str, tier: str) -> str:+ model_dir = os.environ.get(env_name)+ if not model_dir:+ pytest.skip(f"{env_name} is not set; skipping {tier} checkpoint")+ path = Path(model_dir).expanduser()+ if not path.is_dir():+ pytest.skip(f"{env_name} checkpoint not found: {path}")+ return str(path)+++def _chat_ids(engine, messages: list[dict[str, str]]) -> list[int]:+ if hasattr(engine, "encode_chat"):+ return list(engine.encode_chat(messages, think=False))++ tok = engine._tok+ rendered = tok.apply_chat_template(+ messages, tokenize=False, add_generation_prompt=True)+ return list(tok(rendered)["input_ids"])+++def _generate(env_name: str, tier: str,+ messages: list[dict[str, str]]) -> list[int]:+ model_dir = _checkpoint(env_name, tier)+ engine = AutoEngine.from_pretrained(model_dir, name=tier)+ try:+ prompt_ids = _chat_ids(engine, messages)+ started = time.perf_counter()+ output = engine.generate(+ prompt_ids,+ GenerationConfig(+ temperature=0.0,+ top_k=1,+ top_p=1.0,+ max_new_tokens=MAX_NEW_TOKENS,+ ),+ max_new_tokens=MAX_NEW_TOKENS,+ )+ elapsed = time.perf_counter() - started+ tok_s = len(output) / elapsed if elapsed else 0.0+ print(f"[slow] {tier}: {len(output)} tokens in {elapsed:.2f}s "+ f"({tok_s:.1f} tok/s)", flush=True)+ finally:+ engine.close()+ return output+++def test_edge0_8b_real_checkpoint():+ output = _generate(+ "EDGE0_8B_MODEL",+ "edge0-8b",+ [{"role": "user", "content": "你好,请用一句话介绍海滨城市。"}],+ )+ assert output+ assert len(output) <= MAX_NEW_TOKENS+++def test_edge0_35b_real_checkpoint():+ output = _generate(+ "EDGE0_35B_MODEL",+ "edge0-35b",+ [{"role": "user", "content":+ "Hello! Write one short sentence about the seaside."}],+ )+ assert output+ assert len(output) <= MAX_NEW_TOKENS