|
|
import re
|
|
|
|
|
|
class ModelDiagnostics:
|
|
|
@staticmethod
|
|
|
def estimate_vram(param_str):
|
|
|
"""
|
|
|
Estimates VRAM usage based on parameter string (e.g., '7B', '0.5B').
|
|
|
Formula: (Params * Precision Bytes) + 20% Overhead for Context/Activations
|
|
|
"""
|
|
|
try:
|
|
|
|
|
|
clean_str = param_str.lower().replace('b', '').replace('m', '')
|
|
|
val = float(clean_str)
|
|
|
|
|
|
|
|
|
if 'm' in param_str.lower():
|
|
|
val = val / 1000.0
|
|
|
|
|
|
|
|
|
overhead = 1.2
|
|
|
|
|
|
|
|
|
fp16_gb = (val * 2 * overhead)
|
|
|
int8_gb = (val * 1 * overhead)
|
|
|
fp32_gb = (val * 4 * overhead)
|
|
|
|
|
|
return {
|
|
|
"FP32 (Training/Full)": f"{fp32_gb:.2f} GB",
|
|
|
"FP16 (Inference)": f"{fp16_gb:.2f} GB",
|
|
|
"INT8 (Quantized)": f"{int8_gb:.2f} GB",
|
|
|
"params_in_billions": val
|
|
|
}
|
|
|
except Exception as e:
|
|
|
return None
|
|
|
|
|
|
@staticmethod
|
|
|
def get_layer_structure(model):
|
|
|
"""
|
|
|
Returns the raw string representation of the PyTorch model modules.
|
|
|
"""
|
|
|
if model:
|
|
|
|
|
|
return str(model)
|
|
|
return "Model not loaded." |