File size: 1,900 Bytes
a2d6a0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Test de compilación y conteo de params para Mixed Selectivity."""

import sys

sys.path.insert(0, ".")

from pampar.coder.v3.config import PRESET_V3, ConfigV3

# Mixed Selectivity (nueva)
cfg_ms = PRESET_V3
params_ms = cfg_ms.estimate_params()
print("=== Mixed Selectivity ===")
for k, v in params_ms.items():
    print(f"  {k}: {v:>12,}")

# Legacy (4 FFN separados)
cfg_leg = ConfigV3(use_mixed_selectivity=False)
params_leg = cfg_leg.estimate_params()
print("\n=== Legacy (4 FFN) ===")
for k, v in params_leg.items():
    print(f"  {k}: {v:>12,}")

diff = params_leg["total"] - params_ms["total"]
pct = diff / params_leg["total"] * 100
print(f"\nAHORRO: {diff:,} params ({pct:.1f}%)")
total_leg = params_leg["total"] / 1e6
total_ms = params_ms["total"] / 1e6
print(f"Legacy: {total_leg:.1f}M -> Mixed: {total_ms:.1f}M")

# Test de instanciación del modelo completo
print("\n=== Instanciando modelo con Mixed Selectivity... ===")
import torch
from pampar.coder.v3.modelo import PamparV3

model = PamparV3(cfg_ms)
real_params = sum(p.numel() for p in model.parameters())
print(f"Parámetros reales: {real_params:,} ({real_params / 1e6:.1f}M)")

# Test forward pass
print("\n=== Forward pass... ===")
input_ids = torch.randint(0, 48000, (1, 32))
with torch.no_grad():
    logits, loss, info = model(input_ids)
print(f"logits shape: {logits.shape}")
print(f"exit_nivel: {info['exit_nivel']}")
print(f"terr_acts shape: {info['terr_acts'].shape}")

# Verificar que el modelo tiene ffn_shared y modulators
nivel0 = model.niveles[0]
has_shared = hasattr(nivel0, "ffn_shared")
has_mods = hasattr(nivel0, "modulators")
has_legacy = hasattr(nivel0, "ffns")
print(f"\nffn_shared: {has_shared}")
print(f"modulators: {has_mods} (count: {len(nivel0.modulators) if has_mods else 0})")
print(f"ffns (legacy): {has_legacy}")

print("\n=== TODO OK ===")