Megatron-LM icon indicating copy to clipboard operation
Megatron-LM copied to clipboard

On single-GPU training, self.dp_cp_params_list is None, so iterating over it in a for loop throws an error

Open gaojingwei opened this issue 5 months ago • 1 comments

In file: /opt/Megatron-Bridge/3rdparty/Megatron-LM/megatron/core/optimizer/layer_wise_optimizer.py, at LayerWiseDistributedOptimizer::shard_params()

  dp_cp_size = get_pg_size(self.pg_collection.dp_cp)
  if dp_cp_size == 1:
      self.dp_cp_params_list = None                    # it is none!
      self.expt_dp_params_list = None
      return

but at LayerWiseDistributedOptimizer::set_bucket_layerwise_params_list()

for model_chunk in model_chunks:
            for group in model_chunk.bucket_groups:
                for bucket in group.buckets:
                    if not _bucket_is_managed_by_layer_wise_optimizer(bucket):
                        continue
                    bucket_params_list = [[] for _ in range(get_pg_size(self.pg_collection.dp_cp))]
                    for bucket_list, full_params_list in zip(
                        bucket_params_list, self.dp_cp_params_list             #  self.dp_cp_params_list is none, so raise a error.
                    ):
                        for param in full_params_list:
                            if param in bucket.params:
                                bucket_list.append(param)
                    bucket.set_layerwise_params_list(bucket_params_list)

gaojingwei avatar Jun 08 '26 02:06 gaojingwei

Thanks for reporting this bug; we are actively reviewing the two related PRs which aim to fix this bug.

guihong-nv avatar Jun 11 '26 17:06 guihong-nv