Upload slimshard_gui.py
Browse files- slimshard_gui.py +37 -3
slimshard_gui.py
CHANGED
|
@@ -51,6 +51,7 @@ from .slimshard import (
|
|
| 51 |
inspect_recovery_plan,
|
| 52 |
recover_from_shard,
|
| 53 |
regenerate,
|
|
|
|
| 54 |
slimshard_info,
|
| 55 |
)
|
| 56 |
|
|
@@ -922,19 +923,52 @@ class SlimShardGUI:
|
|
| 922 |
|
| 923 |
def test_worker() -> None:
|
| 924 |
try:
|
|
|
|
| 925 |
import torch
|
| 926 |
import torch.nn.functional as F
|
| 927 |
from safetensors.torch import safe_open
|
| 928 |
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
| 929 |
|
| 930 |
t0 = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 931 |
tok = AutoTokenizer.from_pretrained(
|
| 932 |
-
|
| 933 |
)
|
| 934 |
cfg = AutoConfig.from_pretrained(
|
| 935 |
-
|
| 936 |
)
|
| 937 |
-
st_file = Path(mdir) / "model.safetensors"
|
| 938 |
dev = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 939 |
|
| 940 |
# Fast on-demand expert streaming for MXFP8 MoE models, or standard load for generic models
|
|
|
|
| 51 |
inspect_recovery_plan,
|
| 52 |
recover_from_shard,
|
| 53 |
regenerate,
|
| 54 |
+
run_deepseek_v41_generate,
|
| 55 |
slimshard_info,
|
| 56 |
)
|
| 57 |
|
|
|
|
| 923 |
|
| 924 |
def test_worker() -> None:
|
| 925 |
try:
|
| 926 |
+
import json
|
| 927 |
import torch
|
| 928 |
import torch.nn.functional as F
|
| 929 |
from safetensors.torch import safe_open
|
| 930 |
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
| 931 |
|
| 932 |
t0 = time.time()
|
| 933 |
+
mpath = Path(mdir)
|
| 934 |
+
if mpath.is_file() and mpath.suffix == ".safetensors":
|
| 935 |
+
st_file = mpath
|
| 936 |
+
base_dir = mpath.parent
|
| 937 |
+
else:
|
| 938 |
+
base_dir = mpath
|
| 939 |
+
st_file = base_dir / "model.safetensors"
|
| 940 |
+
if not st_file.exists():
|
| 941 |
+
cands = sorted(base_dir.glob("*.safetensors"))
|
| 942 |
+
if cands:
|
| 943 |
+
st_file = cands[0]
|
| 944 |
+
|
| 945 |
+
cfg_file = base_dir / "config.json"
|
| 946 |
+
raw_cfg = json.loads(cfg_file.read_text()) if cfg_file.exists() else {}
|
| 947 |
+
if raw_cfg.get("model_type") == "deepseek_v41":
|
| 948 |
+
decoded, out_list = run_deepseek_v41_generate(
|
| 949 |
+
st_file,
|
| 950 |
+
cfg_file,
|
| 951 |
+
base_dir,
|
| 952 |
+
prompt=prompt,
|
| 953 |
+
max_new_tokens=max_new,
|
| 954 |
+
use_chat_template=use_chat,
|
| 955 |
+
device=self.device_var.get(),
|
| 956 |
+
)
|
| 957 |
+
dt_s = time.time() - t0
|
| 958 |
+
self._queue.put(
|
| 959 |
+
(
|
| 960 |
+
"test_done",
|
| 961 |
+
f"Completed in {dt_s:.2f}s:\n{decoded}\n\nToken IDs: {out_list}",
|
| 962 |
+
)
|
| 963 |
+
)
|
| 964 |
+
return
|
| 965 |
+
|
| 966 |
tok = AutoTokenizer.from_pretrained(
|
| 967 |
+
str(base_dir), trust_remote_code=True, local_files_only=True
|
| 968 |
)
|
| 969 |
cfg = AutoConfig.from_pretrained(
|
| 970 |
+
str(base_dir), trust_remote_code=True, local_files_only=True
|
| 971 |
)
|
|
|
|
| 972 |
dev = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 973 |
|
| 974 |
# Fast on-demand expert streaming for MXFP8 MoE models, or standard load for generic models
|