Skip to content

Conversation

@Ishan-Kumar2
Copy link
Contributor

@Ishan-Kumar2 Ishan-Kumar2 commented Mar 17, 2025

What does this PR do?

Fixes #2466

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? 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.
  • Did you write any new necessary tests?

Who can review?

@qgallouedec @shirinyamani @AIR-hl

Hi everyone, I am new to TRL, have attempted a fix at the issue 2466 here.
The greedy knapsack tries to fit as many examples as possible without overshooting, the remaining ones are chunked as before by breaking it up into smaller example size (<= max_seq_len). Also I havent made this the default packing and kept it under a flag.
Please let me know if this is close to what was expected, I can add tests then, thanks!

@Ishan-Kumar2 Ishan-Kumar2 changed the title Update sft trainer Update sft trainer to include better packing Mar 17, 2025
Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, and sorry for the late reply. I've made some comments. Can you please also:

  • include a test for pack_example_smater
  • modify the packing argument in SFTConfig to allow for this packing method

return knapsacks, [[tup[1]] for tup in numbers]


def pack_examples_smarter(examples: dict[str, list[list]], seq_length: int) -> dict[str, list[list]]:
Copy link
Member

Choose a reason for hiding this comment

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

wdyt of

Suggested change
def pack_examples_smarter(examples: dict[str, list[list]], seq_length: int) -> dict[str, list[list]]:
def pack_examples_knapsack(examples: dict[str, list[list]], seq_length: int) -> dict[str, list[list]]:

or even

Suggested change
def pack_examples_smarter(examples: dict[str, list[list]], seq_length: int) -> dict[str, list[list]]:
def pack_examples_knapsack_greedy(examples: dict[str, list[list]], seq_length: int) -> dict[str, list[list]]:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

Comment on lines 364 to 367
packing: bool,
formatting_func: Optional[Callable[[dict], str]],
dataset_name: str,
pack_smart: bool = False,
Copy link
Member

Choose a reason for hiding this comment

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

maybe this is better:

Suggested change
packing: bool,
formatting_func: Optional[Callable[[dict], str]],
dataset_name: str,
pack_smart: bool = False,
packing: Union[bool, str],
formatting_func: Optional[Callable[[dict], str]],
dataset_name: str,

and use if packing == "knapsack":

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@Ishan-Kumar2
Copy link
Contributor Author

Hi @qgallouedec sorry for the delay, I had my final exams :)
I have made the changes, Please take a look!

@qgallouedec
Copy link
Member

I think we've arrived at something very satisfactory with FFD see #3521, so I'm closing this PR. Thanks for all your hard work!

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.

Probably a more reasonable method of packing

2 participants