"docs/source/vscode:/vscode.git/clone" did not exist on "ace74d16bd576476f57c490522063507daa6ee6a"
Unverified Commit 8e3980a2 authored by Sam Passaglia's avatar Sam Passaglia Committed by GitHub
Browse files

[FIX] resize_token_embeddings (#26102)



* fix roundup command

* add test for resize_token_embeddings

* Update tests/test_modeling_common.py
Co-authored-by: default avatarArthur <48595927+ArthurZucker@users.noreply.github.com>

* style

---------
Co-authored-by: default avatarArthur <48595927+ArthurZucker@users.noreply.github.com>
parent ffbf989f
...@@ -1530,7 +1530,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix ...@@ -1530,7 +1530,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
) )
if new_num_tokens is None: if new_num_tokens is None:
new_num_tokens = old_embeddings.weight.shape[0] new_num_tokens = old_embeddings.weight.shape[0]
new_num_tokens = ((new_num_tokens // pad_to_multiple_of) + 1) * pad_to_multiple_of new_num_tokens = ((new_num_tokens + pad_to_multiple_of - 1) // pad_to_multiple_of) * pad_to_multiple_of
else: else:
logger.warning( logger.warning(
"You are resizing the embedding layer without providing a `pad_to_multiple_of` parameter. This means that the new embedding" "You are resizing the embedding layer without providing a `pad_to_multiple_of` parameter. This means that the new embedding"
......
...@@ -1437,6 +1437,11 @@ class ModelTesterMixin: ...@@ -1437,6 +1437,11 @@ class ModelTesterMixin:
model_embed = model.resize_token_embeddings(model_vocab_size + 13, pad_to_multiple_of=64) model_embed = model.resize_token_embeddings(model_vocab_size + 13, pad_to_multiple_of=64)
self.assertTrue(model_embed.weight.shape[0] // 64, 0) self.assertTrue(model_embed.weight.shape[0] // 64, 0)
# Check that resizing a model to a multiple of pad_to_multiple leads to a model of exactly that size
target_dimension = 128
model_embed = model.resize_token_embeddings(target_dimension, pad_to_multiple_of=64)
self.assertTrue(model_embed.weight.shape[0], target_dimension)
with self.assertRaisesRegex( with self.assertRaisesRegex(
ValueError, ValueError,
"Asking to pad the embedding matrix to a multiple of `1.3`, which is not and integer. Please make sure to pass an integer", "Asking to pad the embedding matrix to a multiple of `1.3`, which is not and integer. Please make sure to pass an integer",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment