(rank: int, world_size: int, rendezvous_file: str, strategy: str, model_path: str)
| 359 | |
| 360 | |
| 361 | def _worker(rank: int, world_size: int, rendezvous_file: str, strategy: str, model_path: str): |
| 362 | torch.cuda.set_device(rank) |
| 363 | dist.init_process_group( |
| 364 | backend="nccl", |
| 365 | init_method=f"file://{rendezvous_file}", |
| 366 | rank=rank, |
| 367 | world_size=world_size, |
| 368 | ) |
| 369 | |
| 370 | ref_model_config = AutoConfig.from_pretrained(model_path) |
| 371 | with torch.device("meta"): |
| 372 | ref_model = AutoModelForCausalLM.from_config(ref_model_config) |
| 373 | |
| 374 | from verl.workers.engine import BaseEngine, EngineRegistry |
| 375 | |
| 376 | # construct configs |
| 377 | model_config = HFModelConfig(path=model_path, load_tokenizer=False) |
| 378 | |
| 379 | if strategy == "megatron": |
| 380 | engine_config = McoreEngineConfig( |
| 381 | forward_only=False, |
| 382 | use_mbridge=True, |
| 383 | tensor_model_parallel_size=2, |
| 384 | pipeline_model_parallel_size=2, |
| 385 | context_parallel_size=1, |
| 386 | ) |
| 387 | optimizer_config = McoreOptimizerConfig(lr_decay_steps=10) |
| 388 | elif strategy in ["fsdp", "fsdp2"]: |
| 389 | engine_config = FSDPEngineConfig( |
| 390 | forward_only=False, fsdp_size=4, strategy=strategy, ulysses_sequence_parallel_size=2 |
| 391 | ) |
| 392 | optimizer_config = FSDPOptimizerConfig() |
| 393 | else: |
| 394 | raise NotImplementedError(f"strategy {strategy} is not supported") |
| 395 | |
| 396 | checkpoint_config = CheckpointConfig() |
| 397 | |
| 398 | # build model engine |
| 399 | engine: BaseEngine = EngineRegistry.new( |
| 400 | model_type="language_model", |
| 401 | backend=engine_config.strategy, |
| 402 | model_config=model_config, |
| 403 | engine_config=engine_config, |
| 404 | optimizer_config=optimizer_config, |
| 405 | checkpoint_config=checkpoint_config, |
| 406 | ) |
| 407 | |
| 408 | engine.initialize() |
| 409 | |
| 410 | # get per tensor parameter |
| 411 | per_tensor_params, _ = engine.get_per_tensor_param() |
| 412 | |
| 413 | ref_state_dict = ref_model.state_dict() |
| 414 | |
| 415 | # load ground truth and compare |
| 416 | for key, value in per_tensor_params: |
| 417 | assert key in ref_state_dict, f"{key} not in ref_state_dict" |
| 418 | assert value.shape == ref_state_dict[key].shape, ( |
nothing calls this directly
no test coverage detected