5454import jax
5555import os
5656from typing import Sequence , Any
57+ import time
58+ from tqdm import tqdm
5759
5860from transformers import AutoTokenizer , AutoProcessor
5961
7274from MaxText .utils .ckpt_conversion .utils .utils import (process_leaf_param , save_model_files , HF_IDS )
7375
7476
75- jax .config .update ("jax_platform_name" , "cpu" )
77+ os .environ ["JAX_PLATFORMS" ] = "cpu"
78+ os .environ ["XLA_FLAGS" ] = "--xla_force_host_platform_device_count=16"
7679
7780
7881def _get_model_mappings (model_name : str , scan_layers : bool , config_dict : dict ):
@@ -114,17 +117,22 @@ def main(argv: Sequence[str]) -> None:
114117 jax .config .update ("jax_default_prng_impl" , "unsafe_rbg" )
115118 os .environ ["TF_CPP_MIN_LOG_LEVEL" ] = "0"
116119
120+ # Initialize maxtext config
117121 config = pyconfig .initialize (argv )
118122 assert (
119123 config .load_full_state_path == ""
120124 ), "This script expects parameters, not a full state. Use generate_param_only_checkpoint first if needed."
121125 max_utils .print_system_information ()
122126
127+ # Load Maxtext checkpoint
128+ max_logging .log ("\n Loading Orbax checkpoint..." )
129+ start = time .time ()
123130 engine = maxengine .MaxEngine (config )
124131 rng = jax .random .PRNGKey (1234 )
125132 rng , rng_load_params = jax .random .split (rng )
126133 # load params from maxengine
127134 loaded_params_from_engine = engine .load_params (rng_load_params )
135+ max_logging .log (f"Elapse: { (time .time () - start ) / 60 :.2f} min" )
128136
129137 if not config .base_output_directory :
130138 output_directory = f"tmp/{ config .run_name } "
@@ -165,18 +173,22 @@ def main(argv: Sequence[str]) -> None:
165173 leaves_with_paths = jax .tree_util .tree_leaves_with_path (actual_weights_dict )
166174
167175 # traverse leavse to build: mt_param_key:mt_weights
176+ max_logging .log ("\n Proccessing weight..." )
177+ start = time .time ()
168178 processed_params_list = []
169- for path_tuple_iter , leaf_value_iter in leaves_with_paths :
170- processed_params_list .extend (
171- process_leaf_param (path_tuple_iter , leaf_value_iter , param_map , shape_map , hook_fn_map , config )
172- )
179+ for path_tuple_iter , leaf_value_iter in tqdm (leaves_with_paths , total = len (leaves_with_paths )):
180+ processed_params = process_leaf_param (path_tuple_iter , leaf_value_iter , param_map , shape_map , hook_fn_map , config )
181+ processed_params_list .extend (processed_params )
173182 transformed_hf_weights = dict (processed_params_list )
183+ max_logging .log (f"Elapse: { (time .time () - start ) / 60 :.2f} min" )
174184
175185 # 5. Save in HuggingFace Format
176186 if not transformed_hf_weights :
177187 print ("Error: No weights were transformed. Check mappings and parameter paths." )
178188 return
179189
190+ max_logging .log ("\n Saving HuggingFace model..." )
191+ start = time .time ()
180192 save_model_files (
181193 weight_arrays = transformed_hf_weights ,
182194 config = hf_config_obj ,
@@ -185,6 +197,7 @@ def main(argv: Sequence[str]) -> None:
185197 output_dir = output_directory ,
186198 )
187199 max_logging .log (f"✅ MaxText model successfully saved in HuggingFace format at { output_directory } " )
200+ max_logging .log (f"Elapse: { (time .time () - start ) / 60 :.2f} min" )
188201
189202
190203if __name__ == "__main__" :
0 commit comments