[Chore] Remove debug code in model implementation (#35883)
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
This commit is contained in:
@@ -2225,104 +2225,6 @@ class NemotronH_Nano_VL_V2(
|
||||
assert len(sound_weights) > 0
|
||||
self.sound_encoder.load_weights(sound_weights)
|
||||
|
||||
def print_architecture(self, detailed: bool = True, save_to_file: str = None):
|
||||
"""
|
||||
Print model architecture with parameter names, shapes, and sizes.
|
||||
|
||||
Args:
|
||||
detailed: If True, show detailed parameter breakdown
|
||||
save_to_file: If provided, save output to this file path
|
||||
"""
|
||||
import sys
|
||||
from io import StringIO
|
||||
|
||||
# Capture output if saving to file
|
||||
original_stdout = sys.stdout
|
||||
if save_to_file:
|
||||
sys.stdout = StringIO()
|
||||
|
||||
try:
|
||||
print("=" * 100)
|
||||
print("NemotronH_Nano_VL_V2 Model Architecture")
|
||||
print("=" * 100)
|
||||
|
||||
total_params = 0
|
||||
param_groups = {
|
||||
"language_model": [],
|
||||
"vision_model": [],
|
||||
"mlp1": [],
|
||||
"other": [],
|
||||
}
|
||||
|
||||
for name, param in self.named_parameters():
|
||||
param_size = param.numel()
|
||||
total_params += param_size
|
||||
|
||||
# Group parameters by main component
|
||||
if name.startswith("language_model"):
|
||||
param_groups["language_model"].append(
|
||||
(name, param.shape, param_size, param.dtype)
|
||||
)
|
||||
elif name.startswith("vision_model"):
|
||||
param_groups["vision_model"].append(
|
||||
(name, param.shape, param_size, param.dtype)
|
||||
)
|
||||
elif name.startswith("mlp1"):
|
||||
param_groups["mlp1"].append(
|
||||
(name, param.shape, param_size, param.dtype)
|
||||
)
|
||||
else:
|
||||
param_groups["other"].append(
|
||||
(name, param.shape, param_size, param.dtype)
|
||||
)
|
||||
|
||||
if detailed:
|
||||
print(
|
||||
f"{name:<70} | Shape: {str(param.shape):<25} | "
|
||||
f"Size: {param_size:>12,} | Dtype: {param.dtype}"
|
||||
)
|
||||
|
||||
print("=" * 100)
|
||||
print("Summary by Component:")
|
||||
print("-" * 60)
|
||||
|
||||
for component, params in param_groups.items():
|
||||
if params: # Only show components that have parameters
|
||||
component_total = sum(size for _, _, size, _ in params)
|
||||
percentage = (
|
||||
(component_total / total_params) * 100
|
||||
if total_params > 0
|
||||
else 0
|
||||
)
|
||||
print(
|
||||
f"{component:<20} | Parameters: {len(params):>4} | "
|
||||
f"Total Size: {component_total:>15,} | "
|
||||
f"{percentage:>6.2f}%"
|
||||
)
|
||||
|
||||
print("-" * 60)
|
||||
print(f"{'Total Parameters':<20} | {total_params:>15,}")
|
||||
|
||||
# Estimate memory usage (assuming bfloat16 = 2 bytes per parameter)
|
||||
memory_mb = total_params * 2 / (1024**2)
|
||||
memory_gb = memory_mb / 1024
|
||||
print(f"{'Est. Memory (MB)':<20} | {memory_mb:>15.2f}")
|
||||
print(f"{'Est. Memory (GB)':<20} | {memory_gb:>15.2f}")
|
||||
print("=" * 100)
|
||||
|
||||
# Save to file if requested
|
||||
if save_to_file:
|
||||
output = sys.stdout.getvalue()
|
||||
sys.stdout = original_stdout
|
||||
with open(save_to_file, "w") as f:
|
||||
f.write(output)
|
||||
print(f"Architecture saved to: {save_to_file}")
|
||||
print(output) # Also print to console
|
||||
|
||||
finally:
|
||||
if save_to_file and sys.stdout != original_stdout:
|
||||
sys.stdout = original_stdout
|
||||
|
||||
def get_vit_model_from_radio_config(self, hf_config):
|
||||
hf_config_vision = hf_config.vision_config
|
||||
model_name = hf_config_vision.args.get("model")
|
||||
|
||||
Reference in New Issue
Block a user