-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm_module_list.py
More file actions
71 lines (62 loc) · 2.65 KB
/
llm_module_list.py
File metadata and controls
71 lines (62 loc) · 2.65 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
from transformers import AutoModel, AutoConfig
config = AutoConfig.from_pretrained('Qwen/Qwen3-VL-Embedding-2B', trust_remote_code=True)
model = AutoModel.from_config(config)
print('=== FULL MODULE TREE OF LAYER 0 ===')
print()
for name, module in model.named_modules():
if name.startswith('layers.0'):
depth = name.count('.') - 1
short = name.split('.')[-1]
cls = module.__class__.__name__
# show param shapes if leaf
params = list(module.named_parameters(recurse=False))
param_info = ''
if params:
param_info = ' params: ' + ', '.join(f'{p[0]}{list(p[1].shape)}' for p in params)
print(f"{' ' * depth}{short:30s} {cls:35s}{param_info}")
print()
print('=== TOP-LEVEL MODULES (outside layers) ===')
for name, module in model.named_modules():
if '.' not in name and name != '':
cls = module.__class__.__name__
params = list(module.named_parameters(recurse=False))
param_info = ''
if params:
param_info = ' params: ' + ', '.join(f'{p[0]}{list(p[1].shape)}' for p in params)
print(f' {name:30s} {cls:35s}{param_info}')
print()
print(f'Total parameters: {sum(p.numel() for p in model.parameters()):,}')
print(f'Total layers: {config.num_hidden_layers}')
#
#
#
from transformers import AutoModel, AutoConfig
config = AutoConfig.from_pretrained('Qwen/Qwen3-VL-Embedding-2B', trust_remote_code=True)
model = AutoModel.from_config(config)
print('=== FULL MODULE TREE OF LAYER 0 ===')
print()
for name, module in model.named_modules():
if name.startswith('language_model.layers.0.'):
depth = name.count('.') - 3
short = name.split('.')[-1]
cls = module.__class__.__name__
# show param shapes if leaf
params = list(module.named_parameters(recurse=False))
param_info = ''
if params:
param_info = ' params: ' + ', '.join(f'{p[0]}{list(p[1].shape)}' for p in params)
print(f"{' ' * depth}{short:30s} {cls:35s}{param_info}")
print()
print('=== TOP-LEVEL MODULES (outside layers) ===')
for name, module in model.named_modules():
if '.' not in name and name != '':
cls = module.__class__.__name__
params = list(module.named_parameters(recurse=False))
param_info = ''
if params:
param_info = ' params: ' + ', '.join(f'{p[0]}{list(p[1].shape)}' for p in params)
print(f' {name:30s} {cls:35s}{param_info}')
print()
print(f'Total parameters: {sum(p.numel() for p in model.parameters()):,}')
num_layers = getattr(config, 'num_hidden_layers', None) or getattr(config.text_config, 'num_hidden_layers', None)
print(f'Total layers: {num_layers}')