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

Fix all output_dir in test_trainer.py to use tmp_dir #35266

Merged
merged 8 commits into from
Jan 8, 2025

Conversation

nhamanasu
Copy link
Contributor

@nhamanasu nhamanasu commented Dec 13, 2024

What does this PR do?

Split from the PR: #35243

Current test_trainer.py has so many direct specifications of outpu_dir to TrainingArguments.
I've replaced all of them with tmp_dir so that no unnecessary folders will be made under root dir.

The targets are:

  • "./examples"
  • "./regression"
  • "./generation"
  • "./test"
  • "None"

Just a random thought

The current CircleCI doesn't seem to include tests for trainer. Is it as intended?

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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@ydshieh @SunMarc

@nhamanasu nhamanasu changed the title Fix all outpu_dir in test_trainer.py to use tmp_dir Fix all output_dir in test_trainer.py to use tmp_dir Dec 13, 2024
@nhamanasu nhamanasu mentioned this pull request Dec 13, 2024
5 tasks
@nhamanasu nhamanasu marked this pull request as ready for review December 13, 2024 18:02
@SunMarc SunMarc requested a review from ydshieh December 23, 2024 11:54
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.

Thanks for making the test cleaner @nhamanasu ! LGTM !

setup.py Outdated Show resolved Hide resolved
src/transformers/dependency_versions_table.py Outdated Show resolved Hide resolved
Comment on lines +4996 to +5002
def test_optim_supported(self, optim: str, expected_cls, expected_kwargs):
with tempfile.TemporaryDirectory() as tmp_dir:
trainer = get_regression_trainer(output_dir=tmp_dir, optim=optim)

trainer = get_regression_trainer(**training_args.to_dict())
trainer.train()
# exercises all the valid --optim options
self.check_optim_and_kwargs(trainer.args, expected_cls, expected_kwargs)
trainer.train()
Copy link
Member

Choose a reason for hiding this comment

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

nice

@SunMarc SunMarc requested a review from ArthurZucker December 23, 2024 16:00
Copy link
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

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

Very nice. Thank you for working on this ❤️ @nhamanasu.

Only a few small nits. Let me know if you want to change accordingly.

Comment on lines 1279 to 1280
with tempfile.TemporaryDirectory() as tmp_dir:
for mix_bf16 in [True, False]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would probably reverse the order of these 2 lines

Comment on lines 1797 to 1798
for name, param in tiny_llama.named_parameters():
self.assertFalse(torch.allclose(param, previous_params[name].to(param.device), rtol=1e-12, atol=1e-12))
Copy link
Collaborator

Choose a reason for hiding this comment

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

the extra indent is not really necessary, but OK to keep this changes

Comment on lines 2390 to 2391
with tempfile.TemporaryDirectory() as tmp_dir:
for mix_bf16 in [True, False]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

better to revert order of 2 lines

Comment on lines 2592 to 2593
with tempfile.TemporaryDirectory() as tmp_dir:
for mix_bf16 in [True, False]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

@nhamanasu
Copy link
Contributor Author

@SunMarc @ydshieh
Thank you for the valuable reviews!
I've fixed the lines pointed out to make them cleaner.

@ydshieh
Copy link
Collaborator

ydshieh commented Jan 8, 2025

Thanks! One more nits: there is no content in .gitignore being modified. Could you avoid it showing up in diff? (or is it intentional?)

After this last point, I will merge

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@nhamanasu
Copy link
Contributor Author

Thanks!
I noticed .gitignore changed too, but I'm not sure why it makes diff... (it's unintentional)

I'm watching the control characters and whitespaces, but I couldn't find any difference.

@nhamanasu
Copy link
Contributor Author

I copied .gitignore from newly cloned transformer repo's main branch, and somehow it fixed the unintentional diff!

Maybe it's related to LF/CRLF or file mode, but I'm not sure in the end...

@ydshieh
Copy link
Collaborator

ydshieh commented Jan 8, 2025

no worry, will merge when CI fishing. Thanks again!

@ydshieh
Copy link
Collaborator

ydshieh commented Jan 8, 2025

Only one test file changed in this PR and the change logic is not involving any real trainer's logic. Will merge

@ydshieh ydshieh merged commit b32938a into huggingface:main Jan 8, 2025
11 checks passed
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.

4 participants