From d89109f502c21bd1f1923eabb5bc5fdc99f8acde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= Date: Mon, 9 Dec 2024 17:50:11 +0000 Subject: [PATCH 1/7] First changes --- examples/datasets/hh-rlhf-helpful-base.py | 2 +- .../lm-human-preferences-descriptiveness.py | 2 +- examples/datasets/lm-human-preferences-sentiment.py | 2 +- examples/datasets/prm800k.py | 2 +- examples/datasets/rlaif-v.py | 2 +- examples/datasets/tldr.py | 2 +- examples/datasets/tldr_preference.py | 2 +- examples/datasets/tokenize_ds.py | 2 +- examples/datasets/ultrafeedback-prompt.py | 2 +- examples/datasets/ultrafeedback.py | 2 +- .../stack_llama/scripts/merge_peft_adapter.py | 2 +- .../stack_llama/scripts/reward_modeling.py | 2 +- .../stack_llama/scripts/rl_training.py | 3 ++- .../stack_llama/scripts/supervised_finetuning.py | 2 +- .../stack_llama_2/scripts/dpo_llama2.py | 2 +- .../stack_llama_2/scripts/sft_llama2.py | 2 +- examples/research_projects/tools/calculator.py | 2 +- .../research_projects/tools/python_interpreter.py | 2 +- examples/research_projects/tools/triviaqa.py | 2 +- .../toxicity/scripts/evaluate-toxicity.py | 2 +- .../toxicity/scripts/gpt-j-6b-toxicity.py | 3 ++- examples/scripts/alignprop.py | 3 ++- examples/scripts/bco.py | 2 +- examples/scripts/chat.py | 1 - examples/scripts/cpo.py | 3 ++- examples/scripts/ddpo.py | 3 ++- examples/scripts/dpo.py | 3 ++- examples/scripts/dpo_online.py | 3 ++- examples/scripts/dpo_vlm.py | 3 ++- examples/scripts/evals/judge_tldr.py | 2 +- examples/scripts/gkd.py | 3 ++- examples/scripts/kto.py | 2 +- examples/scripts/nash_md.py | 3 ++- examples/scripts/orpo.py | 3 ++- examples/scripts/ppo/ppo.py | 2 +- examples/scripts/ppo/ppo_tldr.py | 2 +- examples/scripts/reward_modeling.py | 3 ++- examples/scripts/rloo/rloo.py | 2 +- examples/scripts/rloo/rloo_tldr.py | 2 +- examples/scripts/sft.py | 3 ++- examples/scripts/sft_video_llm.py | 5 +++-- examples/scripts/sft_vlm.py | 3 ++- examples/scripts/sft_vlm_smol_vlm.py | 3 ++- examples/scripts/xpo.py | 3 ++- scripts/add_copyrights.py | 13 +++++-------- scripts/generate_tiny_models.py | 2 +- scripts/generate_zen_dataset.py | 2 +- scripts/log_example_reports.py | 1 + scripts/log_reports.py | 1 + tests/__init__.py | 3 +-- tests/slow/__init__.py | 3 +-- tests/slow/test_dpo_slow.py | 1 + tests/slow/test_sft_slow.py | 1 + tests/slow/testing_constants.py | 1 - tests/test_alignprop_trainer.py | 3 ++- tests/test_bco_trainer.py | 1 + tests/test_best_of_n_sampler.py | 2 +- tests/test_callbacks.py | 2 +- tests/test_cli.py | 3 ++- tests/test_cli_utils.py | 2 +- tests/test_core.py | 3 ++- tests/test_cpo_trainer.py | 1 + tests/test_data_collator_completion_only.py | 3 ++- tests/test_data_utils.py | 1 + tests/test_dataset_formatting.py | 2 +- tests/test_ddpo_trainer.py | 3 ++- tests/test_dpo_trainer.py | 2 +- tests/test_environments.py | 2 +- tests/test_gkd_trainer.py | 1 + 69 files changed, 94 insertions(+), 71 deletions(-) diff --git a/examples/datasets/hh-rlhf-helpful-base.py b/examples/datasets/hh-rlhf-helpful-base.py index 84d8010169..e089ed108e 100644 --- a/examples/datasets/hh-rlhf-helpful-base.py +++ b/examples/datasets/hh-rlhf-helpful-base.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/lm-human-preferences-descriptiveness.py b/examples/datasets/lm-human-preferences-descriptiveness.py index 2620b3101b..621757770c 100644 --- a/examples/datasets/lm-human-preferences-descriptiveness.py +++ b/examples/datasets/lm-human-preferences-descriptiveness.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/lm-human-preferences-sentiment.py b/examples/datasets/lm-human-preferences-sentiment.py index af0359ac38..a3eaa4d06e 100644 --- a/examples/datasets/lm-human-preferences-sentiment.py +++ b/examples/datasets/lm-human-preferences-sentiment.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/prm800k.py b/examples/datasets/prm800k.py index 244257912c..b5f95742be 100644 --- a/examples/datasets/prm800k.py +++ b/examples/datasets/prm800k.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/rlaif-v.py b/examples/datasets/rlaif-v.py index ec2501d4c7..84ae292f87 100644 --- a/examples/datasets/rlaif-v.py +++ b/examples/datasets/rlaif-v.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/tldr.py b/examples/datasets/tldr.py index e386095f88..0ae29481e3 100644 --- a/examples/datasets/tldr.py +++ b/examples/datasets/tldr.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/tldr_preference.py b/examples/datasets/tldr_preference.py index 0ac6af6646..1c4ff5bcbd 100644 --- a/examples/datasets/tldr_preference.py +++ b/examples/datasets/tldr_preference.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/tokenize_ds.py b/examples/datasets/tokenize_ds.py index ae52e0b22c..cd96a685a9 100644 --- a/examples/datasets/tokenize_ds.py +++ b/examples/datasets/tokenize_ds.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/ultrafeedback-prompt.py b/examples/datasets/ultrafeedback-prompt.py index 9753aa620a..3cb92467d5 100644 --- a/examples/datasets/ultrafeedback-prompt.py +++ b/examples/datasets/ultrafeedback-prompt.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/datasets/ultrafeedback.py b/examples/datasets/ultrafeedback.py index 5ca687760a..cb6c556d0c 100644 --- a/examples/datasets/ultrafeedback.py +++ b/examples/datasets/ultrafeedback.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/stack_llama/scripts/merge_peft_adapter.py b/examples/research_projects/stack_llama/scripts/merge_peft_adapter.py index 3d21a95257..f9f8018df7 100644 --- a/examples/research_projects/stack_llama/scripts/merge_peft_adapter.py +++ b/examples/research_projects/stack_llama/scripts/merge_peft_adapter.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/stack_llama/scripts/reward_modeling.py b/examples/research_projects/stack_llama/scripts/reward_modeling.py index db38f62d4c..d3fc3c8505 100644 --- a/examples/research_projects/stack_llama/scripts/reward_modeling.py +++ b/examples/research_projects/stack_llama/scripts/reward_modeling.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/stack_llama/scripts/rl_training.py b/examples/research_projects/stack_llama/scripts/rl_training.py index a37cf63ab1..011c00554f 100644 --- a/examples/research_projects/stack_llama/scripts/rl_training.py +++ b/examples/research_projects/stack_llama/scripts/rl_training.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass, field from typing import Optional diff --git a/examples/research_projects/stack_llama/scripts/supervised_finetuning.py b/examples/research_projects/stack_llama/scripts/supervised_finetuning.py index c2d860468a..48488c8ef3 100644 --- a/examples/research_projects/stack_llama/scripts/supervised_finetuning.py +++ b/examples/research_projects/stack_llama/scripts/supervised_finetuning.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/stack_llama_2/scripts/dpo_llama2.py b/examples/research_projects/stack_llama_2/scripts/dpo_llama2.py index b3d287b144..31cc6bfcbc 100644 --- a/examples/research_projects/stack_llama_2/scripts/dpo_llama2.py +++ b/examples/research_projects/stack_llama_2/scripts/dpo_llama2.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/stack_llama_2/scripts/sft_llama2.py b/examples/research_projects/stack_llama_2/scripts/sft_llama2.py index ef34a67f0c..56170b4818 100644 --- a/examples/research_projects/stack_llama_2/scripts/sft_llama2.py +++ b/examples/research_projects/stack_llama_2/scripts/sft_llama2.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/tools/calculator.py b/examples/research_projects/tools/calculator.py index bde5692f62..5e76ee3416 100644 --- a/examples/research_projects/tools/calculator.py +++ b/examples/research_projects/tools/calculator.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/tools/python_interpreter.py b/examples/research_projects/tools/python_interpreter.py index 8f319b2d68..1870dbfb81 100644 --- a/examples/research_projects/tools/python_interpreter.py +++ b/examples/research_projects/tools/python_interpreter.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/tools/triviaqa.py b/examples/research_projects/tools/triviaqa.py index def5013582..5dadae6beb 100644 --- a/examples/research_projects/tools/triviaqa.py +++ b/examples/research_projects/tools/triviaqa.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/toxicity/scripts/evaluate-toxicity.py b/examples/research_projects/toxicity/scripts/evaluate-toxicity.py index fca714706f..17e25d55ac 100644 --- a/examples/research_projects/toxicity/scripts/evaluate-toxicity.py +++ b/examples/research_projects/toxicity/scripts/evaluate-toxicity.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/research_projects/toxicity/scripts/gpt-j-6b-toxicity.py b/examples/research_projects/toxicity/scripts/gpt-j-6b-toxicity.py index 51f6d284c4..d3998c7882 100644 --- a/examples/research_projects/toxicity/scripts/gpt-j-6b-toxicity.py +++ b/examples/research_projects/toxicity/scripts/gpt-j-6b-toxicity.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass, field from typing import Optional diff --git a/examples/scripts/alignprop.py b/examples/scripts/alignprop.py index 1948080f4b..918619c1e8 100644 --- a/examples/scripts/alignprop.py +++ b/examples/scripts/alignprop.py @@ -1,4 +1,4 @@ -# Copyright 2023 metric-space, The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Total Batch size = 128 = 4 (num_gpus) * 8 (per_device_batch) * 4 (accumulation steps) Feel free to reduce batch size or increasing truncated_rand_backprop_min to a higher value to reduce memory usage. diff --git a/examples/scripts/bco.py b/examples/scripts/bco.py index d37a1fb3a9..b4302148be 100644 --- a/examples/scripts/bco.py +++ b/examples/scripts/bco.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/scripts/chat.py b/examples/scripts/chat.py index d29200055c..34f4ecd0ce 100644 --- a/examples/scripts/chat.py +++ b/examples/scripts/chat.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - import copy import json import os diff --git a/examples/scripts/cpo.py b/examples/scripts/cpo.py index 019e9ef714..5dfb39dcd4 100644 --- a/examples/scripts/cpo.py +++ b/examples/scripts/cpo.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Run the CPO training script with the following command with some example arguments. In general, the optimal configuration for CPO will be similar to that of DPO: diff --git a/examples/scripts/ddpo.py b/examples/scripts/ddpo.py index 92924c51e4..7919d5244a 100644 --- a/examples/scripts/ddpo.py +++ b/examples/scripts/ddpo.py @@ -1,4 +1,4 @@ -# Copyright 2023 metric-space, The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ python examples/scripts/ddpo.py \ --num_epochs=200 \ diff --git a/examples/scripts/dpo.py b/examples/scripts/dpo.py index ed14461725..9552a0ae08 100644 --- a/examples/scripts/dpo.py +++ b/examples/scripts/dpo.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ # Full training python examples/scripts/dpo.py \ diff --git a/examples/scripts/dpo_online.py b/examples/scripts/dpo_online.py index b38e0bc95b..6ea730c9fc 100644 --- a/examples/scripts/dpo_online.py +++ b/examples/scripts/dpo_online.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Usage: diff --git a/examples/scripts/dpo_vlm.py b/examples/scripts/dpo_vlm.py index 0781edd9e3..2b19e35fcc 100644 --- a/examples/scripts/dpo_vlm.py +++ b/examples/scripts/dpo_vlm.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ accelerate launch examples/scripts/dpo_vlm.py \ --dataset_name HuggingFaceH4/rlaif-v_formatted \ diff --git a/examples/scripts/evals/judge_tldr.py b/examples/scripts/evals/judge_tldr.py index 5f6a8ee662..f9e51df729 100644 --- a/examples/scripts/evals/judge_tldr.py +++ b/examples/scripts/evals/judge_tldr.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/scripts/gkd.py b/examples/scripts/gkd.py index ed5d07a47e..a89327d963 100644 --- a/examples/scripts/gkd.py +++ b/examples/scripts/gkd.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ # Full training: python examples/scripts/gkd.py \ diff --git a/examples/scripts/kto.py b/examples/scripts/kto.py index 56205ce57e..e6a09fc539 100644 --- a/examples/scripts/kto.py +++ b/examples/scripts/kto.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/scripts/nash_md.py b/examples/scripts/nash_md.py index d4915e0347..0fc80fa43e 100644 --- a/examples/scripts/nash_md.py +++ b/examples/scripts/nash_md.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Usage: diff --git a/examples/scripts/orpo.py b/examples/scripts/orpo.py index ac3f598f88..886db53d51 100644 --- a/examples/scripts/orpo.py +++ b/examples/scripts/orpo.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Run the ORPO training script with the following command with some example arguments. In general, the optimal configuration for ORPO will be similar to that of DPO without the need for a reference model: diff --git a/examples/scripts/ppo/ppo.py b/examples/scripts/ppo/ppo.py index 3632b1b40d..d43c91b3d7 100644 --- a/examples/scripts/ppo/ppo.py +++ b/examples/scripts/ppo/ppo.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/scripts/ppo/ppo_tldr.py b/examples/scripts/ppo/ppo_tldr.py index 3d8c07ac03..b7c19a25e3 100644 --- a/examples/scripts/ppo/ppo_tldr.py +++ b/examples/scripts/ppo/ppo_tldr.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/scripts/reward_modeling.py b/examples/scripts/reward_modeling.py index ce99964da9..766c7e44f8 100644 --- a/examples/scripts/reward_modeling.py +++ b/examples/scripts/reward_modeling.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Full training: python examples/scripts/reward_modeling.py \ diff --git a/examples/scripts/rloo/rloo.py b/examples/scripts/rloo/rloo.py index a3c685a84b..4f6732b2c6 100644 --- a/examples/scripts/rloo/rloo.py +++ b/examples/scripts/rloo/rloo.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/scripts/rloo/rloo_tldr.py b/examples/scripts/rloo/rloo_tldr.py index 36f759208a..56ea24080d 100644 --- a/examples/scripts/rloo/rloo_tldr.py +++ b/examples/scripts/rloo/rloo_tldr.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/scripts/sft.py b/examples/scripts/sft.py index 422fa89a6f..d68356798b 100644 --- a/examples/scripts/sft.py +++ b/examples/scripts/sft.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ # Full training python examples/scripts/sft.py \ diff --git a/examples/scripts/sft_video_llm.py b/examples/scripts/sft_video_llm.py index 3343c3a302..6e9976ad1c 100644 --- a/examples/scripts/sft_video_llm.py +++ b/examples/scripts/sft_video_llm.py @@ -1,4 +1,4 @@ -# Copyright 2024. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Example usage: accelerate launch \ @@ -49,7 +50,6 @@ import requests import torch -import wandb from datasets import load_dataset from peft import LoraConfig from qwen_vl_utils import process_vision_info @@ -60,6 +60,7 @@ Qwen2VLProcessor, ) +import wandb from trl import ( SFTConfig, SFTTrainer, diff --git a/examples/scripts/sft_vlm.py b/examples/scripts/sft_vlm.py index 49654bc408..330c67b50d 100644 --- a/examples/scripts/sft_vlm.py +++ b/examples/scripts/sft_vlm.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ pip install pillow diff --git a/examples/scripts/sft_vlm_smol_vlm.py b/examples/scripts/sft_vlm_smol_vlm.py index 2cac4f2cac..ad95253edc 100644 --- a/examples/scripts/sft_vlm_smol_vlm.py +++ b/examples/scripts/sft_vlm_smol_vlm.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ pip install pillow diff --git a/examples/scripts/xpo.py b/examples/scripts/xpo.py index d2d3cb05f8..ea57322a61 100644 --- a/examples/scripts/xpo.py +++ b/examples/scripts/xpo.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Usage: diff --git a/scripts/add_copyrights.py b/scripts/add_copyrights.py index 9acd98bea4..e0c39d5988 100644 --- a/scripts/add_copyrights.py +++ b/scripts/add_copyrights.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ from datetime import datetime -COPYRIGHT_HEADER = f"""# Copyright {datetime.now().year} The HuggingFace Inc. team. All rights reserved. +COPYRIGHT_HEADER = f"""# Copyright {datetime.now().year} The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,8 +33,6 @@ # limitations under the License. """ -COPYRIGHT_KEYWORD = "# Copyright 20" - def get_tracked_python_files(): """Get a list of all tracked Python files using git.""" @@ -60,10 +58,9 @@ def check_and_add_copyright(file_path): with open(file_path, encoding="utf-8") as f: content = f.readlines() - # Check if the copyright header exists in the first 10 lines - for line in content[:10]: - if COPYRIGHT_KEYWORD in line: - return True + # Check if the exact copyright header exists + if "".join(content).startswith(COPYRIGHT_HEADER): + return True # If no copyright notice was found, prepend the header print(f"[MODIFY] Adding copyright to {file_path}.") diff --git a/scripts/generate_tiny_models.py b/scripts/generate_tiny_models.py index b15e9f6f65..d70bd51d4c 100644 --- a/scripts/generate_tiny_models.py +++ b/scripts/generate_tiny_models.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/generate_zen_dataset.py b/scripts/generate_zen_dataset.py index e599e6c1ce..73c7c16f82 100644 --- a/scripts/generate_zen_dataset.py +++ b/scripts/generate_zen_dataset.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/log_example_reports.py b/scripts/log_example_reports.py index 10f6c9a7ad..feed6467ca 100644 --- a/scripts/log_example_reports.py +++ b/scripts/log_example_reports.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import argparse import logging import os diff --git a/scripts/log_reports.py b/scripts/log_reports.py index 0cdac4f756..762d057954 100644 --- a/scripts/log_reports.py +++ b/scripts/log_reports.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import argparse import json import logging diff --git a/tests/__init__.py b/tests/__init__.py index adfc257a24..196860c9f1 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/tests/slow/__init__.py b/tests/slow/__init__.py index adfc257a24..196860c9f1 100644 --- a/tests/slow/__init__.py +++ b/tests/slow/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/tests/slow/test_dpo_slow.py b/tests/slow/test_dpo_slow.py index 81e3a8c0d2..b586b90de9 100644 --- a/tests/slow/test_dpo_slow.py +++ b/tests/slow/test_dpo_slow.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import gc import itertools import tempfile diff --git a/tests/slow/test_sft_slow.py b/tests/slow/test_sft_slow.py index ca8f999d57..8759fdb1af 100644 --- a/tests/slow/test_sft_slow.py +++ b/tests/slow/test_sft_slow.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import gc import itertools import tempfile diff --git a/tests/slow/testing_constants.py b/tests/slow/testing_constants.py index cb6dad681c..f1c2ce6b7c 100644 --- a/tests/slow/testing_constants.py +++ b/tests/slow/testing_constants.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# TODO: push them under trl-org MODELS_TO_TEST = [ "trl-internal-testing/tiny-LlamaForCausalLM-3.2", "trl-internal-testing/tiny-MistralForCausalLM-0.2", diff --git a/tests/test_alignprop_trainer.py b/tests/test_alignprop_trainer.py index a7446639d1..092095f919 100644 --- a/tests/test_alignprop_trainer.py +++ b/tests/test_alignprop_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 metric-space, The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import gc import unittest diff --git a/tests/test_bco_trainer.py b/tests/test_bco_trainer.py index 09f274ef65..0442a8f685 100644 --- a/tests/test_bco_trainer.py +++ b/tests/test_bco_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest from functools import partial diff --git a/tests/test_best_of_n_sampler.py b/tests/test_best_of_n_sampler.py index 02d0cb0de7..ab817ab723 100644 --- a/tests/test_best_of_n_sampler.py +++ b/tests/test_best_of_n_sampler.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_callbacks.py b/tests/test_callbacks.py index b0319179b6..d04a7804f8 100644 --- a/tests/test_callbacks.py +++ b/tests/test_callbacks.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_cli.py b/tests/test_cli.py index d288f0f0bf..8330f5d5f8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import subprocess import sys import unittest diff --git a/tests/test_cli_utils.py b/tests/test_cli_utils.py index a2343a2930..ac2f98d519 100644 --- a/tests/test_cli_utils.py +++ b/tests/test_cli_utils.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_core.py b/tests/test_core.py index 2d8531d591..88ecf38fad 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import unittest import torch diff --git a/tests/test_cpo_trainer.py b/tests/test_cpo_trainer.py index ee110c8dab..744ee07aa6 100644 --- a/tests/test_cpo_trainer.py +++ b/tests/test_cpo_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest diff --git a/tests/test_data_collator_completion_only.py b/tests/test_data_collator_completion_only.py index 7e8c6e224e..10c4a1036c 100644 --- a/tests/test_data_collator_completion_only.py +++ b/tests/test_data_collator_completion_only.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import unittest import torch diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index 916417d0f4..a4eb13683c 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import itertools import unittest diff --git a/tests/test_dataset_formatting.py b/tests/test_dataset_formatting.py index b5193bfd92..e2790801b2 100644 --- a/tests/test_dataset_formatting.py +++ b/tests/test_dataset_formatting.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_ddpo_trainer.py b/tests/test_ddpo_trainer.py index 65a626589a..ad4cc60b5e 100644 --- a/tests/test_ddpo_trainer.py +++ b/tests/test_ddpo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 metric-space, The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import gc import unittest diff --git a/tests/test_dpo_trainer.py b/tests/test_dpo_trainer.py index ea9c916d76..fe2c732f64 100644 --- a/tests/test_dpo_trainer.py +++ b/tests/test_dpo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_environments.py b/tests/test_environments.py index 2555f3aeca..0b9fc56867 100644 --- a/tests/test_environments.py +++ b/tests/test_environments.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_gkd_trainer.py b/tests/test_gkd_trainer.py index 8f9e87456b..f6d15aa1ad 100644 --- a/tests/test_gkd_trainer.py +++ b/tests/test_gkd_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import tempfile import unittest From f829937d7a468190c467bdd1e979a61e3365ad68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= Date: Mon, 9 Dec 2024 18:03:31 +0000 Subject: [PATCH 2/7] Other files --- tests/test_iterative_sft_trainer.py | 3 ++- tests/test_judges.py | 3 ++- tests/test_kto_trainer.py | 1 + tests/test_modeling_geometric_mixture_wrapper.py | 1 + tests/test_modeling_value_head.py | 3 ++- tests/test_nash_md_trainer.py | 1 + tests/test_online_dpo_trainer.py | 1 + tests/test_orpo_trainer.py | 1 + tests/test_peft_models.py | 3 ++- tests/test_ppo_trainer.py | 3 ++- tests/test_reward_trainer.py | 3 ++- tests/test_rich_progress_callback.py | 2 +- tests/test_rloo_trainer.py | 3 ++- tests/test_sft_trainer.py | 3 ++- tests/test_trainers_args.py | 2 +- tests/test_utils.py | 2 +- tests/test_xpo_trainer.py | 1 + tests/testing_constants.py | 2 +- tests/testing_utils.py | 3 ++- trl/commands/cli.py | 3 ++- trl/commands/cli_utils.py | 8 +++++--- trl/environment/__init__.py | 2 +- trl/environment/base_environment.py | 2 +- trl/extras/__init__.py | 2 +- trl/extras/best_of_n_sampler.py | 2 +- trl/extras/dataset_formatting.py | 2 +- trl/models/__init__.py | 2 +- trl/models/auxiliary_modules.py | 5 +++-- trl/models/modeling_base.py | 3 ++- trl/models/modeling_sd_base.py | 2 +- trl/models/modeling_value_head.py | 3 ++- trl/models/sd_utils.py | 3 ++- trl/models/utils.py | 2 +- trl/trainer/__init__.py | 2 +- trl/trainer/alignprop_config.py | 2 +- trl/trainer/alignprop_trainer.py | 3 ++- trl/trainer/base.py | 2 +- trl/trainer/bco_config.py | 1 + trl/trainer/bco_trainer.py | 2 +- trl/trainer/callbacks.py | 3 ++- trl/trainer/cpo_config.py | 1 + trl/trainer/cpo_trainer.py | 1 - trl/trainer/ddpo_config.py | 2 +- trl/trainer/ddpo_trainer.py | 2 +- trl/trainer/dpo_config.py | 1 + trl/trainer/dpo_trainer.py | 3 +-- trl/trainer/gkd_config.py | 1 + trl/trainer/gkd_trainer.py | 1 + trl/trainer/iterative_sft_trainer.py | 3 ++- trl/trainer/judges.py | 2 +- trl/trainer/kto_config.py | 1 + trl/trainer/kto_trainer.py | 2 +- trl/trainer/model_config.py | 2 +- trl/trainer/nash_md_trainer.py | 15 +++++++++++++++ trl/trainer/online_dpo_config.py | 2 +- trl/trainer/online_dpo_trainer.py | 2 +- trl/trainer/orpo_config.py | 1 + trl/trainer/orpo_trainer.py | 2 -- trl/trainer/ppo_config.py | 2 +- trl/trainer/ppo_trainer.py | 2 +- trl/trainer/reward_trainer.py | 3 ++- trl/trainer/rloo_config.py | 2 +- trl/trainer/rloo_trainer.py | 2 +- trl/trainer/sft_config.py | 3 ++- trl/trainer/sft_trainer.py | 3 ++- trl/trainer/utils.py | 3 ++- 66 files changed, 104 insertions(+), 57 deletions(-) diff --git a/tests/test_iterative_sft_trainer.py b/tests/test_iterative_sft_trainer.py index 099e058492..f0ee29dbc2 100644 --- a/tests/test_iterative_sft_trainer.py +++ b/tests/test_iterative_sft_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest from functools import partial diff --git a/tests/test_judges.py b/tests/test_judges.py index 13d2164ffe..4789d3bb3a 100644 --- a/tests/test_judges.py +++ b/tests/test_judges.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import time import unittest diff --git a/tests/test_kto_trainer.py b/tests/test_kto_trainer.py index b705d0bc5a..5cb311d272 100644 --- a/tests/test_kto_trainer.py +++ b/tests/test_kto_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest diff --git a/tests/test_modeling_geometric_mixture_wrapper.py b/tests/test_modeling_geometric_mixture_wrapper.py index c3d23b2c9d..97b27885a8 100644 --- a/tests/test_modeling_geometric_mixture_wrapper.py +++ b/tests/test_modeling_geometric_mixture_wrapper.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import unittest import torch diff --git a/tests/test_modeling_value_head.py b/tests/test_modeling_value_head.py index be4932e62f..545f46f95a 100644 --- a/tests/test_modeling_value_head.py +++ b/tests/test_modeling_value_head.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import gc import sys import tempfile diff --git a/tests/test_nash_md_trainer.py b/tests/test_nash_md_trainer.py index c9e100cbb7..c0c0e0664c 100644 --- a/tests/test_nash_md_trainer.py +++ b/tests/test_nash_md_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest diff --git a/tests/test_online_dpo_trainer.py b/tests/test_online_dpo_trainer.py index f29d491769..d5ea8271c5 100644 --- a/tests/test_online_dpo_trainer.py +++ b/tests/test_online_dpo_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest diff --git a/tests/test_orpo_trainer.py b/tests/test_orpo_trainer.py index 6592028ff2..d2eaee3947 100644 --- a/tests/test_orpo_trainer.py +++ b/tests/test_orpo_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest diff --git a/tests/test_peft_models.py b/tests/test_peft_models.py index db29334eda..3149f36bb3 100644 --- a/tests/test_peft_models.py +++ b/tests/test_peft_models.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import tempfile import unittest diff --git a/tests/test_ppo_trainer.py b/tests/test_ppo_trainer.py index 4667b6eb09..ad9b19a7b9 100644 --- a/tests/test_ppo_trainer.py +++ b/tests/test_ppo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import platform import subprocess diff --git a/tests/test_reward_trainer.py b/tests/test_reward_trainer.py index 1cee85b270..d4466a0404 100644 --- a/tests/test_reward_trainer.py +++ b/tests/test_reward_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest diff --git a/tests/test_rich_progress_callback.py b/tests/test_rich_progress_callback.py index 84c287a86d..67deb8d0f1 100644 --- a/tests/test_rich_progress_callback.py +++ b/tests/test_rich_progress_callback.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_rloo_trainer.py b/tests/test_rloo_trainer.py index 05ec037c9e..6861b6e83e 100644 --- a/tests/test_rloo_trainer.py +++ b/tests/test_rloo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import platform import subprocess import tempfile diff --git a/tests/test_sft_trainer.py b/tests/test_sft_trainer.py index d8a3706050..bb0a563d0d 100644 --- a/tests/test_sft_trainer.py +++ b/tests/test_sft_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import copy import os import tempfile diff --git a/tests/test_trainers_args.py b/tests/test_trainers_args.py index b89194d1c9..704a20efad 100644 --- a/tests/test_trainers_args.py +++ b/tests/test_trainers_args.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_utils.py b/tests/test_utils.py index 4d26819058..4488cdc309 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/test_xpo_trainer.py b/tests/test_xpo_trainer.py index b611d93566..0c55025d5e 100644 --- a/tests/test_xpo_trainer.py +++ b/tests/test_xpo_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import tempfile import unittest diff --git a/tests/testing_constants.py b/tests/testing_constants.py index c66f60e569..8b678dadf2 100644 --- a/tests/testing_constants.py +++ b/tests/testing_constants.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/testing_utils.py b/tests/testing_utils.py index c5c8b2e3ce..6c2041b7b3 100644 --- a/tests/testing_utils.py +++ b/tests/testing_utils.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import random import unittest diff --git a/trl/commands/cli.py b/trl/commands/cli.py index 9f4266e631..44a353acec 100644 --- a/trl/commands/cli.py +++ b/trl/commands/cli.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import platform import subprocess diff --git a/trl/commands/cli_utils.py b/trl/commands/cli_utils.py index 772accf0bf..4ed7185671 100644 --- a/trl/commands/cli_utils.py +++ b/trl/commands/cli_utils.py @@ -1,6 +1,4 @@ -# This file is a copy of trl/examples/scripts/sft.py so that we could -# use it together with rich and the TRL CLI in a more customizable manner. -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,6 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# This file is a copy of trl/examples/scripts/sft.py so that we could +# use it together with rich and the TRL CLI in a more customizable manner. + import importlib import inspect import logging diff --git a/trl/environment/__init__.py b/trl/environment/__init__.py index a2a39d747e..673c15fb65 100644 --- a/trl/environment/__init__.py +++ b/trl/environment/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/environment/base_environment.py b/trl/environment/base_environment.py index fa7e21f91b..e230dd6ab6 100644 --- a/trl/environment/base_environment.py +++ b/trl/environment/base_environment.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/extras/__init__.py b/trl/extras/__init__.py index beedbd53f0..2bb2747d2b 100644 --- a/trl/extras/__init__.py +++ b/trl/extras/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/extras/best_of_n_sampler.py b/trl/extras/best_of_n_sampler.py index 646cee1318..c0f02152c2 100644 --- a/trl/extras/best_of_n_sampler.py +++ b/trl/extras/best_of_n_sampler.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/extras/dataset_formatting.py b/trl/extras/dataset_formatting.py index d84db4b49e..1be86580aa 100644 --- a/trl/extras/dataset_formatting.py +++ b/trl/extras/dataset_formatting.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/models/__init__.py b/trl/models/__init__.py index 4cbfc0a511..1c6d01b7d5 100644 --- a/trl/models/__init__.py +++ b/trl/models/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/models/auxiliary_modules.py b/trl/models/auxiliary_modules.py index 98c400c7cc..40b4ca407a 100644 --- a/trl/models/auxiliary_modules.py +++ b/trl/models/auxiliary_modules.py @@ -1,5 +1,5 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. - +# Copyright 2024 The HuggingFace Team. All rights reserved. +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import torch diff --git a/trl/models/modeling_base.py b/trl/models/modeling_base.py index c17b8650de..254fe29ac7 100644 --- a/trl/models/modeling_base.py +++ b/trl/models/modeling_base.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import json import logging import os diff --git a/trl/models/modeling_sd_base.py b/trl/models/modeling_sd_base.py index 0b729a0009..131d8d8016 100644 --- a/trl/models/modeling_sd_base.py +++ b/trl/models/modeling_sd_base.py @@ -1,4 +1,4 @@ -# Copyright 2023 DDPO-pytorch authors (Kevin Black), The HuggingFace Team, metric-space. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/models/modeling_value_head.py b/trl/models/modeling_value_head.py index 592879ae3e..deb1f16f29 100644 --- a/trl/models/modeling_value_head.py +++ b/trl/models/modeling_value_head.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import torch import torch.nn as nn from transformers import AutoModelForCausalLM, AutoModelForSeq2SeqLM, is_torch_npu_available, is_torch_xpu_available diff --git a/trl/models/sd_utils.py b/trl/models/sd_utils.py index a6bbbebf40..8e5c286d54 100644 --- a/trl/models/sd_utils.py +++ b/trl/models/sd_utils.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ State dict utilities: utility methods for converting state dicts easily File copied from diffusers to avoid import issues and make TRL compatible diff --git a/trl/models/utils.py b/trl/models/utils.py index 0ff52461e0..53cf481f1f 100644 --- a/trl/models/utils.py +++ b/trl/models/utils.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/__init__.py b/trl/trainer/__init__.py index e555b107e6..e5599756f7 100644 --- a/trl/trainer/__init__.py +++ b/trl/trainer/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/alignprop_config.py b/trl/trainer/alignprop_config.py index 0efdcc74ce..1c4faa963e 100644 --- a/trl/trainer/alignprop_config.py +++ b/trl/trainer/alignprop_config.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/alignprop_trainer.py b/trl/trainer/alignprop_trainer.py index 0fccba6a53..d03696c091 100644 --- a/trl/trainer/alignprop_trainer.py +++ b/trl/trainer/alignprop_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 AlignProp-pytorch authors (Mihir Prabhudesai), metric-space, The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import textwrap from collections import defaultdict diff --git a/trl/trainer/base.py b/trl/trainer/base.py index f0314cb987..7730e6af9a 100644 --- a/trl/trainer/base.py +++ b/trl/trainer/base.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/bco_config.py b/trl/trainer/bco_config.py index 61729576ec..10cd82b9f5 100644 --- a/trl/trainer/bco_config.py +++ b/trl/trainer/bco_config.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass from typing import Any, Optional diff --git a/trl/trainer/bco_trainer.py b/trl/trainer/bco_trainer.py index 89c2357a19..dc267de882 100644 --- a/trl/trainer/bco_trainer.py +++ b/trl/trainer/bco_trainer.py @@ -1,4 +1,3 @@ -# BCO Authors: Seungjae Jung, Gunsoo Han, Daniel Wontae Nam and Kyoung-Woon On # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import inspect import os import random diff --git a/trl/trainer/callbacks.py b/trl/trainer/callbacks.py index dbee1f60a2..7e25366431 100644 --- a/trl/trainer/callbacks.py +++ b/trl/trainer/callbacks.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os from typing import Optional, Union diff --git a/trl/trainer/cpo_config.py b/trl/trainer/cpo_config.py index 91d3008533..a288a8c75f 100644 --- a/trl/trainer/cpo_config.py +++ b/trl/trainer/cpo_config.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass from typing import Any, Literal, Optional diff --git a/trl/trainer/cpo_trainer.py b/trl/trainer/cpo_trainer.py index 9a068b21ac..49b2849766 100644 --- a/trl/trainer/cpo_trainer.py +++ b/trl/trainer/cpo_trainer.py @@ -1,4 +1,3 @@ -# CPO Authors: Haoran Xu, Amr Sharaf, Yunmo Chen, Weiting Tan, Lingfeng Shen, Benjamin Van Durme, Kenton Murray, Young Jin Kim # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/trl/trainer/ddpo_config.py b/trl/trainer/ddpo_config.py index 442689be8f..ca703eb806 100644 --- a/trl/trainer/ddpo_config.py +++ b/trl/trainer/ddpo_config.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/ddpo_trainer.py b/trl/trainer/ddpo_trainer.py index 4ef0c82c82..a3b6813b4c 100644 --- a/trl/trainer/ddpo_trainer.py +++ b/trl/trainer/ddpo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 DDPO-pytorch authors (Kevin Black), metric-space, The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/dpo_config.py b/trl/trainer/dpo_config.py index 8a6e507dc1..88abdd4a5c 100644 --- a/trl/trainer/dpo_config.py +++ b/trl/trainer/dpo_config.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import warnings from dataclasses import dataclass from enum import Enum diff --git a/trl/trainer/dpo_trainer.py b/trl/trainer/dpo_trainer.py index fe43b133d9..7ed0ac387f 100644 --- a/trl/trainer/dpo_trainer.py +++ b/trl/trainer/dpo_trainer.py @@ -1,5 +1,4 @@ -# DPO Authors: Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, and Chelsea Finn 2023 -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/gkd_config.py b/trl/trainer/gkd_config.py index c826ceade2..e9b9d76363 100644 --- a/trl/trainer/gkd_config.py +++ b/trl/trainer/gkd_config.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass from typing import Any, Optional diff --git a/trl/trainer/gkd_trainer.py b/trl/trainer/gkd_trainer.py index bc4f35ef33..173a8d6107 100644 --- a/trl/trainer/gkd_trainer.py +++ b/trl/trainer/gkd_trainer.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import random import textwrap diff --git a/trl/trainer/iterative_sft_trainer.py b/trl/trainer/iterative_sft_trainer.py index d2b02ab33b..9621822eb8 100644 --- a/trl/trainer/iterative_sft_trainer.py +++ b/trl/trainer/iterative_sft_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import warnings from typing import Callable, Optional, Union diff --git a/trl/trainer/judges.py b/trl/trainer/judges.py index 71f86ef1b3..c29491340d 100644 --- a/trl/trainer/judges.py +++ b/trl/trainer/judges.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/kto_config.py b/trl/trainer/kto_config.py index 351885c362..563d0cdbc9 100644 --- a/trl/trainer/kto_config.py +++ b/trl/trainer/kto_config.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass from typing import Any, Literal, Optional diff --git a/trl/trainer/kto_trainer.py b/trl/trainer/kto_trainer.py index 5513cf8d08..3aa3396e39 100644 --- a/trl/trainer/kto_trainer.py +++ b/trl/trainer/kto_trainer.py @@ -1,4 +1,3 @@ -# KTO Authors: Kawin Ethayarajh, Winnie Xu, Niklas Muennighoff, Dan Jurafsky, and Douwe Kiela # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import inspect import os import random diff --git a/trl/trainer/model_config.py b/trl/trainer/model_config.py index 7301d10213..3261ff8a6a 100644 --- a/trl/trainer/model_config.py +++ b/trl/trainer/model_config.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/nash_md_trainer.py b/trl/trainer/nash_md_trainer.py index a37f4bb170..1e10018fa7 100644 --- a/trl/trainer/nash_md_trainer.py +++ b/trl/trainer/nash_md_trainer.py @@ -12,6 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. + +# Copyright 2024 The HuggingFace Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import textwrap from typing import Any, Callable, Optional, Union diff --git a/trl/trainer/online_dpo_config.py b/trl/trainer/online_dpo_config.py index 34f8ec5837..0b06c79cb5 100644 --- a/trl/trainer/online_dpo_config.py +++ b/trl/trainer/online_dpo_config.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/online_dpo_trainer.py b/trl/trainer/online_dpo_trainer.py index 7830d3fe64..3d2b85536e 100644 --- a/trl/trainer/online_dpo_trainer.py +++ b/trl/trainer/online_dpo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/orpo_config.py b/trl/trainer/orpo_config.py index 16aafbc787..b7e2ef7ad0 100644 --- a/trl/trainer/orpo_config.py +++ b/trl/trainer/orpo_config.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass from typing import Any, Optional diff --git a/trl/trainer/orpo_trainer.py b/trl/trainer/orpo_trainer.py index e90fec8dfe..e6f148f90f 100644 --- a/trl/trainer/orpo_trainer.py +++ b/trl/trainer/orpo_trainer.py @@ -1,5 +1,3 @@ -# ORPO Authors: Jiwoo Hong, Noah Lee, and James Thorne -# Official code: https://github.com/xfactlab/orpo # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/trl/trainer/ppo_config.py b/trl/trainer/ppo_config.py index 465048184b..62a3b0a33e 100644 --- a/trl/trainer/ppo_config.py +++ b/trl/trainer/ppo_config.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/ppo_trainer.py b/trl/trainer/ppo_trainer.py index 2b55e5797c..b51c29c014 100644 --- a/trl/trainer/ppo_trainer.py +++ b/trl/trainer/ppo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/reward_trainer.py b/trl/trainer/reward_trainer.py index 4000697336..3157900b83 100644 --- a/trl/trainer/reward_trainer.py +++ b/trl/trainer/reward_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import inspect import os import warnings diff --git a/trl/trainer/rloo_config.py b/trl/trainer/rloo_config.py index 2683fb5eee..e72b0fc02c 100644 --- a/trl/trainer/rloo_config.py +++ b/trl/trainer/rloo_config.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/rloo_trainer.py b/trl/trainer/rloo_trainer.py index f2e3eb9674..6ad38d37c4 100644 --- a/trl/trainer/rloo_trainer.py +++ b/trl/trainer/rloo_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/trainer/sft_config.py b/trl/trainer/sft_config.py index eefc22b267..310ede7870 100644 --- a/trl/trainer/sft_config.py +++ b/trl/trainer/sft_config.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from dataclasses import dataclass from typing import Any, Optional diff --git a/trl/trainer/sft_trainer.py b/trl/trainer/sft_trainer.py index 34a95f36ec..809eff5679 100644 --- a/trl/trainer/sft_trainer.py +++ b/trl/trainer/sft_trainer.py @@ -1,4 +1,4 @@ -# Copyright 2023 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import dataclasses import inspect import os diff --git a/trl/trainer/utils.py b/trl/trainer/utils.py index d1cc3a0e9d..2473b9a8e2 100644 --- a/trl/trainer/utils.py +++ b/trl/trainer/utils.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import dataclasses import importlib.resources as pkg_resources import json From 83247232d98bcb495e145427eec1deba24bccb37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= Date: Mon, 9 Dec 2024 18:05:55 +0000 Subject: [PATCH 3/7] Finally --- setup.py | 2 +- trl/__init__.py | 2 +- trl/core.py | 3 ++- trl/data_utils.py | 1 + trl/env_utils.py | 34 ---------------------------------- trl/import_utils.py | 3 ++- trl/utils.py | 2 +- 7 files changed, 8 insertions(+), 39 deletions(-) delete mode 100644 trl/env_utils.py diff --git a/setup.py b/setup.py index 1259911368..01b9fdb485 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/__init__.py b/trl/__init__.py index 25cf4fb291..8976eb2603 100644 --- a/trl/__init__.py +++ b/trl/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/trl/core.py b/trl/core.py index d4e77f5fdc..f62c8bc414 100644 --- a/trl/core.py +++ b/trl/core.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import gc import random import warnings diff --git a/trl/data_utils.py b/trl/data_utils.py index 88319626b8..9bc68f1d5c 100644 --- a/trl/data_utils.py +++ b/trl/data_utils.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from typing import Any, Optional, Sequence, TypeVar from datasets import Dataset, DatasetDict diff --git a/trl/env_utils.py b/trl/env_utils.py deleted file mode 100644 index 64e98199e0..0000000000 --- a/trl/env_utils.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Function `strtobool` copied and adapted from `distutils` (as deprected -# in Python 3.10). -# Reference: https://github.com/python/cpython/blob/48f9d3e3faec5faaa4f7c9849fecd27eae4da213/Lib/distutils/util.py#L308-L321 - - -def strtobool(val: str) -> bool: - """Convert a string representation of truth to True or False booleans. - - True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values - are 'n', 'no', 'f', 'false', 'off', and '0'. - - Raises: - ValueError: if 'val' is anything else. - """ - val = val.lower() - if val in ("y", "yes", "t", "true", "on", "1"): - return True - if val in ("n", "no", "f", "false", "off", "0"): - return False - raise ValueError(f"Invalid truth value, it should be a string but {val} was provided instead.") diff --git a/trl/import_utils.py b/trl/import_utils.py index 31b78899f7..6ec64260e3 100644 --- a/trl/import_utils.py +++ b/trl/import_utils.py @@ -1,4 +1,4 @@ -# Copyright 2022 The HuggingFace Team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import importlib import os from itertools import chain diff --git a/trl/utils.py b/trl/utils.py index 6888e56229..b63742d2ac 100644 --- a/trl/utils.py +++ b/trl/utils.py @@ -1,4 +1,4 @@ -# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 1e36f946f386cd0a446e6510a18d234dd697b68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= Date: Mon, 9 Dec 2024 18:08:43 +0000 Subject: [PATCH 4/7] rm comment --- trl/commands/cli_utils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/trl/commands/cli_utils.py b/trl/commands/cli_utils.py index 4ed7185671..d899011a6f 100644 --- a/trl/commands/cli_utils.py +++ b/trl/commands/cli_utils.py @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This file is a copy of trl/examples/scripts/sft.py so that we could -# use it together with rich and the TRL CLI in a more customizable manner. - import importlib import inspect import logging From 98f7a7ff1d01575045da8557b213ada34febbcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= Date: Mon, 9 Dec 2024 18:09:41 +0000 Subject: [PATCH 5/7] fix nashmd --- trl/trainer/nash_md_trainer.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/trl/trainer/nash_md_trainer.py b/trl/trainer/nash_md_trainer.py index 1e10018fa7..a37f4bb170 100644 --- a/trl/trainer/nash_md_trainer.py +++ b/trl/trainer/nash_md_trainer.py @@ -12,21 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - -# Copyright 2024 The HuggingFace Team. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - import os import textwrap from typing import Any, Callable, Optional, Union From 71f232481f9612e9fea7c3984e56fb89acfc474e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= Date: Mon, 9 Dec 2024 18:31:37 +0000 Subject: [PATCH 6/7] Fix example --- examples/scripts/sft_video_llm.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/examples/scripts/sft_video_llm.py b/examples/scripts/sft_video_llm.py index 6e9976ad1c..03bf5ffe79 100644 --- a/examples/scripts/sft_video_llm.py +++ b/examples/scripts/sft_video_llm.py @@ -50,24 +50,13 @@ import requests import torch +import wandb from datasets import load_dataset from peft import LoraConfig from qwen_vl_utils import process_vision_info -from transformers import ( - AutoModelForVision2Seq, - AutoProcessor, - BitsAndBytesConfig, - Qwen2VLProcessor, -) +from transformers import AutoModelForVision2Seq, AutoProcessor, BitsAndBytesConfig, Qwen2VLProcessor -import wandb -from trl import ( - SFTConfig, - SFTTrainer, - get_kbit_device_map, -) -from trl.commands.cli_utils import SFTScriptArguments, TrlParser -from trl.trainer import ModelConfig +from trl import ModelConfig, SFTConfig, SFTTrainer, TrlParser, get_kbit_device_map def download_video(url: str, cache_dir: str) -> str: From 161f6dea96f55b681607902499506d95a931a134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= Date: Mon, 9 Dec 2024 18:33:48 +0000 Subject: [PATCH 7/7] Fix example [ci skip] --- examples/scripts/sft_video_llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/scripts/sft_video_llm.py b/examples/scripts/sft_video_llm.py index 03bf5ffe79..8cb8864e44 100644 --- a/examples/scripts/sft_video_llm.py +++ b/examples/scripts/sft_video_llm.py @@ -56,7 +56,7 @@ from qwen_vl_utils import process_vision_info from transformers import AutoModelForVision2Seq, AutoProcessor, BitsAndBytesConfig, Qwen2VLProcessor -from trl import ModelConfig, SFTConfig, SFTTrainer, TrlParser, get_kbit_device_map +from trl import ModelConfig, ScriptArguments, SFTConfig, SFTTrainer, TrlParser, get_kbit_device_map def download_video(url: str, cache_dir: str) -> str: @@ -151,7 +151,7 @@ def collate_fn(examples: list[dict[str, Any]]) -> dict[str, torch.Tensor]: @dataclass -class CustomScriptArguments(SFTScriptArguments): +class CustomScriptArguments(ScriptArguments): video_cache_dir: str = "/tmp/videos/"