Load a config that describes a model with topology and slices to be dumped.
(argv: Sequence[str])
| 256 | |
| 257 | |
| 258 | def main(argv: Sequence[str]) -> None: |
| 259 | """Load a config that describes a model with topology and slices to be dumped.""" |
| 260 | jax.config.update("jax_default_prng_impl", "unsafe_rbg") |
| 261 | os.environ["LIBTPU_INIT_ARGS"] = ( |
| 262 | os.environ.get("LIBTPU_INIT_ARGS", "") + " --xla_tpu_spmd_rng_bit_generator_unsafe=true" |
| 263 | ) |
| 264 | print("Starting sharding_tests.py...", flush=True) |
| 265 | |
| 266 | config = pyconfig.initialize(argv) |
| 267 | validate_config(config) |
| 268 | |
| 269 | json_path = ( |
| 270 | f"sharding_info/{config.model_name}/" |
| 271 | f"{config.compile_topology}/" |
| 272 | f"slice_{config.compile_topology_num_slices}/" |
| 273 | f"named_shardings.json" |
| 274 | ) |
| 275 | |
| 276 | try: |
| 277 | topology_mesh = get_topology_mesh(config) |
| 278 | _, _, state_mesh_shardings, _ = get_shaped_inputs(topology_mesh, config) |
| 279 | except: # pylint: disable=bare-except |
| 280 | state_mesh_shardings = {} |
| 281 | |
| 282 | if state_mesh_shardings == {}: |
| 283 | return |
| 284 | |
| 285 | sharding_dict = named_shardings_to_json(state_mesh_shardings) |
| 286 | save_named_sharding_dict(json_path, sharding_dict) |
| 287 | load_named_sharding_json(json_path) |
| 288 | print(config.model_name, config.compile_topology) |
| 289 | |
| 290 | |
| 291 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected