Skip to content

Commit

Permalink
fix CLIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lenglaender committed Jan 14, 2025
1 parent e7de20b commit 0d3f0a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/adapters/model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1679,13 +1679,10 @@ def gradient_checkpointing_function(function, *args, **kwargs):
try:
self.enable_input_require_grads()
except NotImplementedError:
# Some models (CLIP) don't have input embeddings, so Hugging Face's implementation raises a NotImplementedError.
logger.warning(
"Model does not have input embeddings. Hugging Face didn't implement the model.enable_input_require_grads() method. But Gradient Checkpointing should nevertheless work. If you, however, encounter errors / weird behaviour, this might be the reason. In this case, please implement the method in the model yourself / open an issue on our GitHub."
# Some models (CLIP) don't have input embeddings, so Hugging Face's implementation raises a NotImplementedError. We provide the user with some more information.
raise NotImplementedError(
"Model has no enable_input_require_grads method implementation by Hugging Face. Parameter efficient fine-tuning however needs gradients for embeddings. This model therefore doesn't support gradient checkpointing with Adapters nor Hugging Face's PEFT library."
)
except Exception as e:
# Every other exception is unexpected and should be raised.
raise e
# >>> END AH Changes <<<


Expand Down
5 changes: 5 additions & 0 deletions tests/models/test_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ def test_initialization(self):
[0.0, 1.0],
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
)

def test_gradient_checkpointing_enable_disable(self):
# CLIPAdapterModel does not support gradient checkpointing (because enable_input_require_grads is not implemented by Hugging Face,
# which is required for gradient checkpointing with parameter efficient fine-tuning methods).
self.skipTest("CLIPAdapterModel does not support gradient checkpointing")

0 comments on commit 0d3f0a1

Please sign in to comment.