Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mlc_llm/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# pylint: disable=missing-docstring,invalid-name
import argparse
import json
import math
import os
import shutil
from typing import Any, Dict, List, Optional, Set

import numpy as np

import tvm
from tvm import relax

Expand Down Expand Up @@ -269,11 +272,12 @@ def save_params(params: List[tvm.nd.NDArray], artifact_path: str) -> None:
meta_data["ParamSize"] = len(params)
total_size = 0.0
for i, nd in enumerate(params):
assert nd is not None, f"Missing parameter at index {i}"
param_dict[f"param_{i}"] = nd
np_nd = nd.numpy()
total_size += np_nd.size * np_nd.dtype.itemsize
total_size = total_size / 1024.0 / 1024.0 / 1024.0
print(f"Total param size: {total_size} GB")

total_size_bytes = sum(math.prod(param.shape) * np.dtype(param.dtype).itemsize for param in params)
total_size_gb = total_size_bytes / (1024 ** 3)
print(f"Total param size: {total_size_gb} GB")
tvmjs.dump_ndarray_cache(
param_dict, f"{artifact_path}/params", meta_data=meta_data, encode_format="raw"
)
Expand Down