bihmoe-poc / src /bihmoe /utils /misc.py
Throstur
probe: add minimal dense + structured models and VRAM probe script
14847f9
Raw
History Blame Contribute Delete
604 Bytes
from __future__ import annotations
import os
import random
import numpy as np
def set_seed(seed: int) -> None:
random.seed(seed)
np.random.seed(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
try:
import torch
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
except Exception:
pass
def count_params(module) -> int:
return sum(p.numel() for p in module.parameters())
def fmt_bytes(n: int) -> str:
for unit in ["B","KB","MB","GB","TB"]:
if n < 1024:
return f"{n:.1f}{unit}"
n /= 1024
return f"{n:.1f}PB"