Compare commits

...

1 Commits

Author SHA1 Message Date
3c7b6e7f02 Breakout fix of #2481 for #2477, patch release prep (#2497)
This change is a breakout of the changes in PR #2481 to form a patch release.
There are no additional tests but the HF_HUB_OFFLINE feature was merged to improve the CI experience.

* Testing common uses situational HF_HUB_OFFLINE (#2490)

Employ offline mode when the model was already accessed once from the hub in order to speed up the CI and make the process less prone to rate limiting.

The idea here is that we can mark contexts that, once they were visited once for a specific model id, we can assume that they are cached locally and can set HF_HUB_OFFLINE=1 for this context. This PR tests this concept for testing_common which is already a big chunk of the tests and probably has the biggest gain given the amount of change.

We already saw that the assumption does not always hold true: for the prompt tuning tests (_test_prepare_input_for_generation) there is a case where one time the tokenizer is not used for model X and after that time the tokenizer is used - since we're setting the hub to offline for the second time the tokenizer from_pretrained call will fail. This problem is alleviated by adding the tokenizer name to the model id as cache identifier.

(cherry picked from commit 10839648629571ef0bbcaed627e320765b871293)
(Removed delete adapter tests)
2025-04-15 16:55:13 +02:00
5 changed files with 882 additions and 765 deletions

View File

@ -15,7 +15,7 @@
from setuptools import find_packages, setup
VERSION = "0.15.1"
VERSION = "0.15.2"
extras = {}
extras["quality"] = [

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.15.1"
__version__ = "0.15.2"
from .auto import (
MODEL_TYPE_TO_PEFT_MODEL_MAPPING,

View File

@ -953,7 +953,7 @@ class PeftModel(PushToHubMixin, torch.nn.Module):
else:
self.modules_to_save.update(peft_config.modules_to_save)
# this may add a new ModulesToSaveWrapper
_set_trainable(self, adapter_name, module_names=peft_config.modules_to_save)
_set_trainable(self, adapter_name, module_names=getattr(peft_config, "modules_to_save", None))
if getattr(peft_config, "trainable_token_indices", None) is not None:
if isinstance(peft_config.trainable_token_indices, dict):
@ -1497,13 +1497,14 @@ class PeftModelForSequenceClassification(PeftModel):
else:
peft_config.modules_to_save.extend(classifier_module_names)
for name, _ in self.base_model.named_children():
if any(module_name in name for module_name in self.modules_to_save):
self.cls_layer_name = name
break
if self.modules_to_save:
for name, _ in self.base_model.named_children():
if any(module_name in name for module_name in self.modules_to_save):
self.cls_layer_name = name
break
# to make sure classifier layer is trainable; this may add a new ModulesToSaveWrapper
_set_trainable(self, adapter_name, module_names=peft_config.modules_to_save)
_set_trainable(self, adapter_name, module_names=getattr(peft_config, "modules_to_save", None))
def add_adapter(self, adapter_name: str, peft_config: PeftConfig, low_cpu_mem_usage: bool = False) -> None:
"""
@ -2288,13 +2289,14 @@ class PeftModelForTokenClassification(PeftModel):
else:
peft_config.modules_to_save.extend(classifier_module_names)
for name, _ in self.base_model.named_children():
if any(module_name in name for module_name in self.modules_to_save):
self.cls_layer_name = name
break
if self.modules_to_save is not None:
for name, _ in self.base_model.named_children():
if any(module_name in name for module_name in self.modules_to_save):
self.cls_layer_name = name
break
# to make sure classifier layer is trainable; this may add a new ModulesToSaveWrapper
_set_trainable(self, adapter_name, module_names=peft_config.modules_to_save)
_set_trainable(self, adapter_name, module_names=getattr(peft_config, "modules_to_save", None))
def add_adapter(self, adapter_name: str, peft_config: PeftConfig, low_cpu_mem_usage: bool = False) -> None:
"""
@ -2515,7 +2517,7 @@ class PeftModelForQuestionAnswering(PeftModel):
break
# to make sure classifier layer is trainable; this may add a new ModulesToSaveWrapper
_set_trainable(self, adapter_name, module_names=peft_config.modules_to_save)
_set_trainable(self, adapter_name, module_names=getattr(peft_config, "modules_to_save", None))
def add_adapter(self, adapter_name: str, peft_config: PeftConfig, low_cpu_mem_usage: bool = False) -> None:
"""

View File

@ -749,6 +749,9 @@ def _set_trainable(
if wrapper_cls is None:
wrapper_cls = ModulesToSaveWrapper
if module_names is None:
return
trainable_modules = []
found_modules = set()
# disable removal of duplicates to support targeting tied weights

File diff suppressed because it is too large Load Diff