From 8eabbac857bcb36ca0679672bfbe2258ab9398fb Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 15 Aug 2026 15:05:26 +0000 Subject: [PATCH] =?UTF-8?q?test:=20probe=5Fmodel=5Fshapes.sh=20=E2=80=94?= =?UTF-8?q?=20=E7=9C=9F=E6=9C=BA=E9=AA=8C=E8=AF=81=E6=A8=A1=E5=9E=8Bconfig?= =?UTF-8?q?=E5=92=8CMoE=E6=9D=83=E9=87=8Dshape?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- probe_model_shapes.sh | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 probe_model_shapes.sh diff --git a/probe_model_shapes.sh b/probe_model_shapes.sh new file mode 100755 index 00000000..2633a063 --- /dev/null +++ b/probe_model_shapes.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -e + +echo "=== 模型权重实际shape ===" +python3 -c " +import torch, os, json +# 读config.json +cfg_path = '/model/config.json' +if os.path.exists(cfg_path): + with open(cfg_path) as f: + cfg = json.load(f) + print('Model config:') + for k in ['hidden_size', 'intermediate_size', 'num_attention_heads', + 'num_key_value_heads', 'num_hidden_layers', 'num_experts', + 'num_experts_per_tok', 'moe_intermediate_size', 'vocab_size', + 'max_position_embeddings']: + print(f' {k}: {cfg.get(k, \"N/A\")}') +else: + print(f'{cfg_path} not found') + # 搜索 + import glob + for p in glob.glob('/model/**/config.json', recursive=True): + print(f' found: {p}') +" + +echo "" +echo "=== safetensor权重shape(第一个shard)===" +python3 -c " +from safetensors import safe_open +import glob, os +shards = sorted(glob.glob('/model/model*.safetensors')) +if not shards: + shards = sorted(glob.glob('/model/*.safetensors')) +if shards: + print(f'Found {len(shards)} shards, reading first: {shards[0]}') + with safe_open(shards[0], framework='pt') as f: + for key in sorted(f.keys()): + if 'experts' in key and ('w1' in key or 'w2' in key or 'w13' in key): + print(f' {key}: {f.get_tensor(key).shape}') + break # 只看一个就够了 + # 也看gate + for key in sorted(f.keys()): + if 'gate' in key and 'weight' in key: + print(f' {key}: {f.get_tensor(key).shape}') + break +else: + print('No safetensor shards found') +" 2>&1 || echo "safetensors not available"