Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: why duplicate PID appears on rank 0 #6111

Open
1 task done
ericxsun opened this issue Nov 3, 2024 · 3 comments
Open
1 task done

[BUG]: why duplicate PID appears on rank 0 #6111

ericxsun opened this issue Nov 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ericxsun
Copy link
Contributor

ericxsun commented Nov 3, 2024

Is there an existing issue for this bug?

  • I have searched the existing issues

🐛 Describe the bug

When using the GeminiPlugin to train a model, it runs normally at the start. However, once a checkpoint(shard) is saved, a duplicate PID appears on rank 0.

Start:
image

After Saved Checkpoint

image

Why and how to avoid it ? Thanks a lot

Environment

Torch: 2.1.2
Colossalai: 0.4.2
Python: 3.8
Cuda: 12.1.0

@ericxsun ericxsun added the bug Something isn't working label Nov 3, 2024
@ericxsun ericxsun changed the title [BUG]: why the PID duplicate to other gpus [BUG]: why duplicate PID appears on rank 0 Nov 3, 2024
@ericxsun
Copy link
Contributor Author

ericxsun commented Nov 3, 2024

While dig into, I found that when saving the optimizer, the PIDs from other ranks appear on rank 0.

torch.cuda.empty_cache()
booster.save_optimizer(optimizer, path_optimizer, shard=True, size_per_shard=2048)

@ericxsun
Copy link
Contributor Author

ericxsun commented Nov 4, 2024

I observed that, following this line:

compacted_states = self.pack_optimizer_states_to_tensor(param_id, state_names) if own_param else None
, the PID for other ranks starts appearing on rank-0

Furthermore, after reaching this line:

compacted_states = torch.zeros(compacted_size, dtype=dtype, device=device, requires_grad=False)

If device is replaced with torch.device(f"cuda:{torch.cuda.current_device()}"), each rank retains only one PID, just as at the start.

compacted_states = torch.zeros(
    compacted_size,
    dtype=dtype,
    device=torch.device(f"cuda:{torch.cuda.current_device()}"),
    requires_grad=False
) 

And after reaching this line:

dist.all_gather_object(gathered_state_shards, [compacted_states, shard_offset, shard_size], group=zero_group)

the PID for other ranks still starts appearing on each rank.

@ericxsun
Copy link
Contributor Author

ericxsun commented Nov 4, 2024

any Colossalai-ers could help me? Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant