Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions megatron/training/datasets/sft_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,12 @@ def extend_with_padding(tokens, targets, positions, pad_len):

# Handle any necessary truncation
if len(pack_tokens) >= pack_length + 1: # +1 here to account for later alignment
truncate_left_not_right = True # TODO(duncan): plumb this switch in
if truncate_left_not_right: # Retain existing eod
max_body = pack_length
pack_tokens = pack_tokens[-max_body:]
pack_targets = pack_targets[-max_body:]
pack_tokens.append(pad)
pack_targets.append(pad)
else: # Truncate right (need to add eod)
max_body = pack_length - 1
pack_tokens = pack_tokens[:max_body]
pack_targets = pack_targets[:max_body]
pack_tokens.extend([eod, pad])
pack_targets.extend([eod, pad])
# Truncate on the right
max_body = pack_length
pack_tokens = pack_tokens[:max_body]
pack_targets = pack_targets[:max_body]
pack_tokens.extend(pad)
pack_targets.extend(pad)

@hsiehjackson hsiehjackson Jan 31, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pad is an integer and should be a list as follows

pack_tokens.extend([pad])
pack_targets.extend([pad])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

I'll change it to .append(pad) in another PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@hsiehjackson, I opened 3185. GitHub is not allowing me to select you as a reviewer. I don't know why. Please review that.

pack_positions = pack_positions[:pack_length+1]
# Note len({pack_tokens, pack_targets, pack_positions}) should be pack_length + 1
cu_seqlens[-1] = len(pack_tokens) - 1
Expand Down
Loading