-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdebug_discovery.py
More file actions
167 lines (144 loc) · 6.27 KB
/
Copy pathdebug_discovery.py
File metadata and controls
167 lines (144 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
"""Debug script to see what models are discovered and how tag matching works.
Usage:
python3 debug_discovery.py [TAG]
Arguments:
TAG: Optional tag to test (default: MAD/dummy_multi)
Examples:
python3 debug_discovery.py
python3 debug_discovery.py MAD/dummy_multi
python3 debug_discovery.py MAD-private/some_model
"""
import sys
import os
import argparse
# Try to import from installed package first, then fall back to src/
try:
from madengine.utils.discover_models import DiscoverModels
except ImportError:
# Not installed, try from src/ (development mode)
sys.path.insert(0, 'src')
try:
from madengine.utils.discover_models import DiscoverModels
except ImportError:
print("ERROR: Cannot import madengine. Either:")
print(" 1. Run 'pip install -e .' from madengine repository, or")
print(" 2. Run this script from madengine repository root")
sys.exit(1)
# Show current directory context
print("=" * 60)
print("DEBUGGING MODEL DISCOVERY")
print("=" * 60)
print(f"Current directory: {os.getcwd()}")
print(f"Scripts directory exists: {os.path.exists('scripts')}")
print(f"Root models.json exists: {os.path.exists('models.json')}")
if os.path.exists('scripts'):
print(f"\nContents of scripts/:")
for item in os.listdir('scripts'):
item_path = os.path.join('scripts', item)
if os.path.isdir(item_path):
print(f" 📁 {item}/")
# Check if it has models.json
models_json = os.path.join(item_path, 'models.json')
if os.path.exists(models_json):
print(f" ✓ has models.json")
# Check for nested scripts
nested_scripts = os.path.join(item_path, 'scripts')
if os.path.exists(nested_scripts):
print(f" ✓ has scripts/ subdirectory")
else:
print(f" 📄 {item}")
print()
dm = DiscoverModels(args=argparse.Namespace(tags=None))
try:
dm.discover_models()
print(f"\n✅ Discovery successful! Found {len(dm.models)} models\n")
print("All discovered models:")
print("-" * 60)
for i, model in enumerate(dm.models, 1):
print(f"{i}. Name: {model['name']}")
print(f" Tags: {model.get('tags', [])}")
print(f" Scripts: {model.get('scripts', 'N/A')}")
print(f" Internal fs_path: {model.get('_fs_rel_path', 'N/A')}")
print()
# Now try with the specific tag
test_tag = sys.argv[1] if len(sys.argv) > 1 else 'MAD/dummy_multi'
print("\n" + "=" * 60)
print(f"TESTING TAG: {test_tag}")
print("=" * 60)
dm2 = DiscoverModels(args=argparse.Namespace(tags=[test_tag]))
dm2.discover_models()
# Parse the tag to check expected matches
if '/' in test_tag:
scope, tag_filter = test_tag.split('/', 1)
prefix = scope + "/"
full_name_match = prefix + tag_filter
dir_prefix_match = full_name_match + "/"
print(f"\nModels that start with '{scope}/':")
scope_models = [m for m in dm2.models if m['name'].startswith(prefix)]
if scope_models:
for model in scope_models:
print(f" - {model['name']}")
else:
print(f" (none found)")
print(f"\nModels that start with '{dir_prefix_match}':")
dir_models = [m for m in dm2.models if m['name'].startswith(dir_prefix_match)]
if dir_models:
for model in dir_models:
print(f" - {model['name']}")
else:
print(f" (none found)")
print(f"\nAttempting selection with tag '{test_tag}'...")
try:
dm2.select_models()
print(f"✅ SUCCESS! Selected {len(dm2.selected_models)} models:")
for model in dm2.selected_models:
print(f" - {model['name']}")
except ValueError as e:
print(f"❌ FAILED: {e}")
print("\nDEBUG: Checking why no matches...")
# Parse the scoped tag if applicable
if '/' in test_tag:
scope, tag_filter = test_tag.split('/', 1)
prefix = scope + "/"
full_name_match = prefix + tag_filter
dir_prefix_match = full_name_match + "/"
print(f" Scope: {scope}")
print(f" Tag filter: {tag_filter}")
print(f" Prefix: {prefix}")
print(f" Full name match: {full_name_match}")
print(f" Dir prefix match: {dir_prefix_match}")
print(f"\n Checking each model:")
for model in dm2.models:
name = model['name']
has_tags = model.get('tags', [])
starts_with_prefix = name.startswith(prefix)
is_all = tag_filter == 'all'
has_tag = tag_filter in has_tags if isinstance(has_tags, list) else False
is_exact = name == full_name_match
is_dir_match = name.startswith(dir_prefix_match)
# Check path component matching
path_after_scope = name[len(prefix):] if starts_with_prefix else ""
path_components = path_after_scope.split("/") if path_after_scope else []
has_component_match = tag_filter in path_components
print(f"\n Model: {name}")
print(f" Starts with '{prefix}': {starts_with_prefix}")
if starts_with_prefix:
print(f" Path after scope: {path_after_scope}")
print(f" Path components: {path_components}")
print(f" Tag field has '{tag_filter}': {has_tag}")
print(f" Is exact match '{full_name_match}': {is_exact}")
print(f" Starts with dir '{dir_prefix_match}': {is_dir_match}")
print(f" Has component match '{tag_filter}': {has_component_match}")
print(f" Would match: {is_all or has_tag or is_exact or is_dir_match or has_component_match}")
else:
# Unscoped tag
print(f" Tag '{test_tag}' is unscoped.")
print(f" Models with this tag in their 'tags' field:")
for model in dm2.models:
if test_tag in model.get('tags', []):
print(f" - {model['name']}")
except Exception as e:
print(f"\n❌ Discovery failed: {e}")
import traceback
traceback.print_exc()