Skip to content

Conversation

@kmehant
Copy link
Contributor

@kmehant kmehant commented Nov 29, 2025

What does this PR do?

  1. does batch padding to cp_size * 2 with shift_label calculation (we can omit this if you think this has to be outside the train loop)
  2. adds cp accelerate context
  3. loss calculation for cp and cp + dp cases

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Signed-off-by: Mehant Kammakomati <mehant.kammakomati2@ibm.com>
@kmehant kmehant changed the title feat: allow cp with trainer feat: allow CP with trainer Nov 29, 2025
Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment !

Comment on lines +2521 to +2542
cp_context = contextlib.nullcontext()
if self.accelerator.parallelism_config and self.accelerator.parallelism_config.cp_enabled:
cp_size_multiple = self.accelerator.parallelism_config.cp_size * 2
max_length = (
(inputs["input_ids"].shape[1] + (cp_size_multiple - 1)) // cp_size_multiple
) * cp_size_multiple
inputs = self._pad_batch(inputs, max_length=max_length)
cp_context = self.accelerator.maybe_context_parallel(
buffers=[
inputs["input_ids"],
inputs["shift_labels"],
inputs["labels"],
inputs["position_ids"],
],
buffer_seq_dims=[1, 1, 1, 1],
no_restore_buffers={
inputs["input_ids"],
inputs["shift_labels"],
inputs["labels"],
inputs["position_ids"],
},
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have _prepare_context_parallel_inputs in training_step ! If things needs to be changed, it's better to do it there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants