ScottzillaSystems commited on
Commit
3b60a91
·
verified ·
1 Parent(s): bbb9941

Add model diagnostic script for Agent Zero debugging

Browse files
Files changed (1) hide show
  1. debug_models.py +233 -0
debug_models.py ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Agent Zero Model Diagnostics — Tests loading each model from the catalog.
4
+ Run this on CPU to identify config/tokenizer issues before deploying to ZeroGPU.
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import json
10
+ import traceback
11
+ from typing import Dict, Any
12
+
13
+ # Install deps
14
+ import subprocess
15
+ subprocess.run([sys.executable, "-m", "pip", "install", "-q",
16
+ "transformers>=4.52.0", "accelerate>=0.30.0", "torch", "huggingface-hub>=0.25.0"],
17
+ capture_output=True)
18
+
19
+ import torch
20
+ from transformers import (
21
+ AutoModelForCausalLM,
22
+ AutoTokenizer,
23
+ AutoProcessor,
24
+ AutoModelForImageTextToText,
25
+ AutoConfig,
26
+ )
27
+ from huggingface_hub import HfApi
28
+
29
+ HF_TOKEN = os.getenv("HF_TOKEN")
30
+ if not HF_TOKEN:
31
+ print("❌ ERROR: HF_TOKEN not set!")
32
+ sys.exit(1)
33
+
34
+ print(f"✅ HF_TOKEN present (length: {len(HF_TOKEN)})")
35
+ print(f"✅ PyTorch version: {torch.__version__}")
36
+ print(f"✅ CUDA available: {torch.cuda.is_available()}")
37
+
38
+ import transformers
39
+ print(f"✅ Transformers version: {transformers.__version__}")
40
+
41
+ # Model catalog
42
+ MODELS = {
43
+ "chatgpt5-494m": {
44
+ "repo": "ScottzillaSystems/ChatGPT-5",
45
+ "architecture": "causal_lm",
46
+ "size": "494M",
47
+ },
48
+ "qwen3.5-9b-opus": {
49
+ "repo": "ScottzillaSystems/Huihui-Qwen3.5-9B-Claude-4.6-Opus-abliterated",
50
+ "architecture": "conditional_gen",
51
+ "size": "9.6B",
52
+ },
53
+ "supergemma4-7.5b": {
54
+ "repo": "ScottzillaSystems/supergemma4-e4b-abliterated",
55
+ "architecture": "conditional_gen",
56
+ "size": "7.5B",
57
+ },
58
+ "cydonia-24b": {
59
+ "repo": "ScottzillaSystems/Cydonia-24B-v4.1",
60
+ "architecture": "causal_lm",
61
+ "size": "24B",
62
+ },
63
+ "qwen3.6-27b": {
64
+ "repo": "ScottzillaSystems/Huihui-Qwen3.6-27B-abliterated",
65
+ "architecture": "conditional_gen",
66
+ "size": "27.8B",
67
+ },
68
+ "qwen3-vl-8b": {
69
+ "repo": "ScottzillaSystems/Huihui-Qwen3-VL-8B-Instruct-abliterated",
70
+ "architecture": "conditional_gen",
71
+ "size": "8.8B",
72
+ },
73
+ "qwen3.5-9b-base": {
74
+ "repo": "ScottzillaSystems/Qwen3.5-9B",
75
+ "architecture": "conditional_gen",
76
+ "size": "9.6B",
77
+ },
78
+ }
79
+
80
+ results = {}
81
+
82
+ print("\n" + "=" * 80)
83
+ print("PHASE 1: Check model configs (no download, just metadata)")
84
+ print("=" * 80)
85
+
86
+ for key, model_info in MODELS.items():
87
+ repo = model_info["repo"]
88
+ print(f"\n{'─' * 60}")
89
+ print(f"Testing: {key} ({repo})")
90
+ print(f"{'─' * 60}")
91
+
92
+ result = {"repo": repo, "config_ok": False, "tokenizer_ok": False,
93
+ "chat_template_ok": False, "errors": []}
94
+
95
+ # Test 1: Load config
96
+ try:
97
+ config = AutoConfig.from_pretrained(repo, trust_remote_code=True, token=HF_TOKEN)
98
+ arch = config.architectures[0] if hasattr(config, 'architectures') and config.architectures else "unknown"
99
+ model_type = getattr(config, 'model_type', 'unknown')
100
+ print(f" ✅ Config loaded: arch={arch}, model_type={model_type}")
101
+ result["config_ok"] = True
102
+ result["architecture_actual"] = arch
103
+ result["model_type"] = model_type
104
+ except Exception as e:
105
+ print(f" ❌ Config FAILED: {type(e).__name__}: {e}")
106
+ result["errors"].append(f"Config: {type(e).__name__}: {e}")
107
+ results[key] = result
108
+ continue
109
+
110
+ # Test 2: Load tokenizer/processor
111
+ try:
112
+ if model_info["architecture"] == "conditional_gen":
113
+ tokenizer = AutoProcessor.from_pretrained(repo, trust_remote_code=True, token=HF_TOKEN)
114
+ print(f" ✅ AutoProcessor loaded")
115
+ else:
116
+ tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True, token=HF_TOKEN)
117
+ if tokenizer.pad_token is None:
118
+ tokenizer.pad_token = tokenizer.eos_token
119
+ print(f" ✅ AutoTokenizer loaded")
120
+ result["tokenizer_ok"] = True
121
+ result["tokenizer_type"] = type(tokenizer).__name__
122
+ except Exception as e:
123
+ print(f" ❌ Tokenizer/Processor FAILED: {type(e).__name__}: {e}")
124
+ traceback.print_exc()
125
+ result["errors"].append(f"Tokenizer: {type(e).__name__}: {e}")
126
+
127
+ # Try alternative loading
128
+ print(f" 🔄 Trying alternative loading...")
129
+ try:
130
+ if model_info["architecture"] == "conditional_gen":
131
+ tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True, token=HF_TOKEN)
132
+ print(f" ⚠️ AutoTokenizer works instead of AutoProcessor!")
133
+ result["tokenizer_ok"] = True
134
+ result["tokenizer_type"] = f"FALLBACK: {type(tokenizer).__name__}"
135
+ result["errors"].append("AutoProcessor failed but AutoTokenizer works")
136
+ else:
137
+ tokenizer = AutoProcessor.from_pretrained(repo, trust_remote_code=True, token=HF_TOKEN)
138
+ print(f" ⚠️ AutoProcessor works instead of AutoTokenizer!")
139
+ result["tokenizer_ok"] = True
140
+ result["tokenizer_type"] = f"FALLBACK: {type(tokenizer).__name__}"
141
+ except Exception as e2:
142
+ print(f" ❌ Alternative also FAILED: {type(e2).__name__}: {e2}")
143
+ result["errors"].append(f"Alt tokenizer: {type(e2).__name__}: {e2}")
144
+
145
+ # Test 3: Chat template
146
+ if result["tokenizer_ok"]:
147
+ try:
148
+ test_messages = [
149
+ {"role": "user", "content": "Hello, how are you?"}
150
+ ]
151
+ text = tokenizer.apply_chat_template(
152
+ test_messages, tokenize=False, add_generation_prompt=True
153
+ )
154
+ print(f" ✅ Chat template works (output length: {len(text)} chars)")
155
+ print(f" First 200 chars: {repr(text[:200])}")
156
+ result["chat_template_ok"] = True
157
+ result["chat_template_sample"] = text[:200]
158
+ except Exception as e:
159
+ print(f" ❌ Chat template FAILED: {type(e).__name__}: {e}")
160
+ traceback.print_exc()
161
+ result["errors"].append(f"Chat template: {type(e).__name__}: {e}")
162
+
163
+ # Test 4: Tokenization
164
+ if result["tokenizer_ok"] and result["chat_template_ok"]:
165
+ try:
166
+ if model_info["architecture"] == "conditional_gen":
167
+ inputs = tokenizer(text=[text], return_tensors="pt", padding=True)
168
+ else:
169
+ inputs = tokenizer(text, return_tensors="pt", padding=True)
170
+
171
+ tensor_keys = [k for k in inputs.keys() if hasattr(inputs[k], 'shape')]
172
+ for k in tensor_keys:
173
+ print(f" ✅ Input '{k}': shape={inputs[k].shape}, dtype={inputs[k].dtype}")
174
+ result["tokenization_ok"] = True
175
+ except Exception as e:
176
+ print(f" ❌ Tokenization FAILED: {type(e).__name__}: {e}")
177
+ traceback.print_exc()
178
+ result["errors"].append(f"Tokenization: {type(e).__name__}: {e}")
179
+ result["tokenization_ok"] = False
180
+
181
+ # Test 5: Check which Auto class would load this model
182
+ try:
183
+ # Detect which class transformers would use
184
+ if arch in ["Qwen2ForCausalLM", "MistralForCausalLM", "LlamaForCausalLM"]:
185
+ result["recommended_loader"] = "AutoModelForCausalLM"
186
+ elif "ForConditionalGeneration" in arch or "ForImageTextToText" in arch:
187
+ result["recommended_loader"] = "AutoModelForImageTextToText"
188
+ else:
189
+ result["recommended_loader"] = f"Unknown for {arch}"
190
+ print(f" ℹ️ Recommended loader: {result['recommended_loader']}")
191
+ except Exception as e:
192
+ pass
193
+
194
+ results[key] = result
195
+
196
+ # Summary
197
+ print("\n\n" + "=" * 80)
198
+ print("SUMMARY")
199
+ print("=" * 80)
200
+
201
+ for key, r in results.items():
202
+ status_parts = []
203
+ if r["config_ok"]:
204
+ status_parts.append("config✅")
205
+ else:
206
+ status_parts.append("config❌")
207
+ if r.get("tokenizer_ok"):
208
+ status_parts.append("tokenizer✅")
209
+ else:
210
+ status_parts.append("tokenizer❌")
211
+ if r.get("chat_template_ok"):
212
+ status_parts.append("chat_tmpl✅")
213
+ else:
214
+ status_parts.append("chat_tmpl❌")
215
+ if r.get("tokenization_ok"):
216
+ status_parts.append("tokenize✅")
217
+ else:
218
+ status_parts.append("tokenize❌")
219
+
220
+ status = " | ".join(status_parts)
221
+ emoji = "✅" if all([r["config_ok"], r.get("tokenizer_ok"), r.get("chat_template_ok"), r.get("tokenization_ok")]) else "❌"
222
+ print(f" {emoji} {key}: {status}")
223
+ if r.get("errors"):
224
+ for err in r["errors"]:
225
+ print(f" └─ {err}")
226
+ if r.get("recommended_loader"):
227
+ print(f" └─ Loader: {r['recommended_loader']}")
228
+
229
+ # Dump full results as JSON
230
+ print("\n\n" + "=" * 80)
231
+ print("FULL RESULTS JSON:")
232
+ print("=" * 80)
233
+ print(json.dumps(results, indent=2, default=str))