Skip to content

Commit 0a8081b

Browse files
authored
[Modeling] Fix encoder CPU offloading for whisper (#38994)
* fix cpu offloading for whisper Signed-off-by: Kyle Sayers <[email protected]> * unskip offloading tests Signed-off-by: Kyle Sayers <[email protected]> * revert small change Signed-off-by: Kyle Sayers <[email protected]> * remove tests Signed-off-by: Kyle Sayers <[email protected]> --------- Signed-off-by: Kyle Sayers <[email protected]>
1 parent c63cfd6 commit 0a8081b

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

src/transformers/models/whisper/modeling_whisper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,9 @@ def forward(
687687
inputs_embeds = nn.functional.gelu(self.conv2(inputs_embeds))
688688

689689
inputs_embeds = inputs_embeds.permute(0, 2, 1)
690-
embed_pos = self.embed_positions.weight
690+
all_positions = torch.arange(self.embed_positions.num_embeddings, device=inputs_embeds.device)
691691

692-
hidden_states = inputs_embeds + embed_pos
692+
hidden_states = inputs_embeds + self.embed_positions(all_positions)
693693
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
694694

695695
encoder_states = () if output_hidden_states else None

tests/models/whisper/test_modeling_whisper.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,22 +3356,6 @@ def test_forward_pass_weighted_layer_sum(self):
33563356
config_and_inputs = self.model_tester.prepare_config_and_inputs()
33573357
self.model_tester.create_and_check_model_forward(*config_and_inputs, use_weighted_layer_sum=True)
33583358

3359-
@unittest.skip(reason="Some undefined behavior encountered with tiny versions of this model. Skip for now.")
3360-
def test_cpu_offload(self):
3361-
pass
3362-
3363-
@unittest.skip(reason="Some undefined behavior encountered with tiny versions of this model. Skip for now.")
3364-
def test_disk_offload_bin(self):
3365-
pass
3366-
3367-
@unittest.skip(reason="Some undefined behavior encountered with tiny versions of this model. Skip for now.")
3368-
def test_disk_offload_safetensors(self):
3369-
pass
3370-
3371-
@unittest.skip(reason="Some undefined behavior encountered with tiny versions of this model. Skip for now.")
3372-
def test_model_parallelism(self):
3373-
pass
3374-
33753359
@unittest.skip(reason="Not applicable for an encoder-only acoustic model")
33763360
def test_inputs_embeds(self):
33773361
# input embeds is meaningless for an encoder-only acoustic model

0 commit comments

Comments
 (0)