Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/kernels/dsv4/test_dsv4_load.py # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `MojoLlama / src / mojollama / kernels / dsv4 / test_dsv4_load.py` 58 lines ยท 2150 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Test loading DeepSeek V4 Flash - just metadata and a few tensors.""" 3 import sys, os 4 sys.path.insert(0, '/onedev-workspace/work/src') 5 6 from mojollama.kernels.turbo_engine_dsv4 import SafetensorsLoader, DeepSeekV4Config 7 8 cfg = DeepSeekV4Config(n_layers=1) 9 print(f"Config: {cfg}") 10 11 print("Loading metadata...") 12 loader = SafetensorsLoader(cfg.model_id) 13 print(f"Loaded {len(loader.shard_of)} tensor entries across {len(loader._shard_cache)} shards") 14 15 # Check if we can load the embed weight 16 print("\nLoading embed.weight...") 17 try: 18 embed = loader.get_tensor('embed.weight') 19 print(f" embed.weight: {embed.shape}, {embed.dtype}, {embed.nbytes/1e6:.1f} MB") 20 except Exception as e: 21 print(f" Error: {e}") 22 23 # Check a few layer 0 tensors 24 print("\nLoading layer 0 weights...") 25 for name in ['attn_norm.weight', 'attn.wq_a.qweight', 'attn.wq_a.qzeros', 'attn.wq_a.scales', 26 'attn.wkv.qweight']: 27 try: 28 t = loader.get_tensor(f"layers.0.{name}") 29 print(f" layers.0.{name}: {t.shape}, {t.dtype}") 30 except KeyError as e: 31 print(f" layers.0.{name}: NOT FOUND") 32 33 # Try dequantizing one weight 34 print("\nTesting W4A16 dequantize...") 35 from mojollama.kernels.turbo_engine_dsv4 import dequantize_w4a16 36 try: 37 qw = loader.get_tensor('layers.0.attn.wq_a.qweight') 38 qz = loader.get_tensor('layers.0.attn.wq_a.qzeros') 39 sc = loader.get_tensor('layers.0.attn.wq_a.scales') 40 print(f" qweight: {qw.shape}, qzeros: {qz.shape}, scales: {sc.shape}") 41 deq = dequantize_w4a16(qw, qz, sc) 42 print(f" dequantized: {deq.shape}, mean={deq.mean():.4f}, std={deq.std():.4f}") 43 except Exception as e: 44 print(f" Error: {e}") 45 import traceback; traceback.print_exc() 46 47 # Check a few expert weights 48 print("\nLoading expert weights for layer 0...") 49 for expert_id in [0, 1, 2]: 50 for wname in ['w1', 'w2', 'w3']: 51 try: 52 t = loader.get_tensor(f"layers.0.ffn.experts.{expert_id}.{wname}.qweight") 53 print(f" expert {expert_id} {wname}: {t.shape}") 54 except KeyError: 55 print(f" expert {expert_id} {wname}: NOT FOUND") 56 57 loader.close() 58 print("\nDone!")