From 040e700153b3226b9b50df9073aa85b1f3db9efe Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 3 Jan 2022 19:56:26 +0100 Subject: [PATCH 1/4] fix doc example - AttributeError: 'numpy.ndarray' object has no attribute 'to' --- src/transformers/models/wav2vec2/modeling_wav2vec2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/transformers/models/wav2vec2/modeling_wav2vec2.py b/src/transformers/models/wav2vec2/modeling_wav2vec2.py index 2d56647f4a9453..3dba7f9d892740 100755 --- a/src/transformers/models/wav2vec2/modeling_wav2vec2.py +++ b/src/transformers/models/wav2vec2/modeling_wav2vec2.py @@ -1460,6 +1460,7 @@ def forward( >>> batch_size, raw_sequence_length = input_values.shape >>> sequence_length = model._get_feat_extract_output_lengths(raw_sequence_length) >>> mask_time_indices = _compute_mask_indices((batch_size, sequence_length), mask_prob=0.2, mask_length=2) + >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.bool) >>> with torch.no_grad(): ... outputs = model(input_values, mask_time_indices=mask_time_indices) From 637abd386afd68176d322981e134f420a9ffeb28 Mon Sep 17 00:00:00 2001 From: ydshieh Date: Tue, 4 Jan 2022 09:59:34 +0100 Subject: [PATCH 2/4] fix more --- src/transformers/models/unispeech/modeling_unispeech.py | 1 + src/transformers/models/unispeech_sat/modeling_unispeech_sat.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/transformers/models/unispeech/modeling_unispeech.py b/src/transformers/models/unispeech/modeling_unispeech.py index 5dfd73a3d34a85..f55bc73e9b38bf 100755 --- a/src/transformers/models/unispeech/modeling_unispeech.py +++ b/src/transformers/models/unispeech/modeling_unispeech.py @@ -1290,6 +1290,7 @@ def forward( >>> batch_size, raw_sequence_length = input_values.shape >>> sequence_length = model._get_feat_extract_output_lengths(raw_sequence_length) >>> mask_time_indices = _compute_mask_indices((batch_size, sequence_length), mask_prob=0.2, mask_length=2) + >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.bool) >>> with torch.no_grad(): ... outputs = model(input_values, mask_time_indices=mask_time_indices) diff --git a/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py b/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py index efdd35725bdc72..72b817ca62f194 100755 --- a/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py +++ b/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py @@ -1322,6 +1322,7 @@ def forward( >>> batch_size, raw_sequence_length = input_values.shape >>> sequence_length = model._get_feat_extract_output_lengths(raw_sequence_length) >>> mask_time_indices = _compute_mask_indices((batch_size, sequence_length), mask_prob=0.2, mask_length=2) + >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.bool) >>> with torch.no_grad(): ... outputs = model(input_values, mask_time_indices=mask_time_indices) From a6f68f462f1d53944b3edb87b49d7e197e2998ed Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 4 Jan 2022 19:13:05 +0100 Subject: [PATCH 3/4] Apply suggestions from code review --- src/transformers/models/unispeech_sat/modeling_unispeech_sat.py | 2 +- src/transformers/models/wav2vec2/modeling_wav2vec2.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py b/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py index 72b817ca62f194..d49aa29f500066 100755 --- a/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py +++ b/src/transformers/models/unispeech_sat/modeling_unispeech_sat.py @@ -1322,7 +1322,7 @@ def forward( >>> batch_size, raw_sequence_length = input_values.shape >>> sequence_length = model._get_feat_extract_output_lengths(raw_sequence_length) >>> mask_time_indices = _compute_mask_indices((batch_size, sequence_length), mask_prob=0.2, mask_length=2) - >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.bool) + >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.long) >>> with torch.no_grad(): ... outputs = model(input_values, mask_time_indices=mask_time_indices) diff --git a/src/transformers/models/wav2vec2/modeling_wav2vec2.py b/src/transformers/models/wav2vec2/modeling_wav2vec2.py index 3dba7f9d892740..b82df05b8f7f3f 100755 --- a/src/transformers/models/wav2vec2/modeling_wav2vec2.py +++ b/src/transformers/models/wav2vec2/modeling_wav2vec2.py @@ -1460,7 +1460,7 @@ def forward( >>> batch_size, raw_sequence_length = input_values.shape >>> sequence_length = model._get_feat_extract_output_lengths(raw_sequence_length) >>> mask_time_indices = _compute_mask_indices((batch_size, sequence_length), mask_prob=0.2, mask_length=2) - >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.bool) + >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.long) >>> with torch.no_grad(): ... outputs = model(input_values, mask_time_indices=mask_time_indices) From c814cdffa4d3e01d4af48cb8c8437bce966904df Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Tue, 4 Jan 2022 19:13:29 +0100 Subject: [PATCH 4/4] Update src/transformers/models/unispeech/modeling_unispeech.py --- src/transformers/models/unispeech/modeling_unispeech.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformers/models/unispeech/modeling_unispeech.py b/src/transformers/models/unispeech/modeling_unispeech.py index f55bc73e9b38bf..81ef40653a8672 100755 --- a/src/transformers/models/unispeech/modeling_unispeech.py +++ b/src/transformers/models/unispeech/modeling_unispeech.py @@ -1290,7 +1290,7 @@ def forward( >>> batch_size, raw_sequence_length = input_values.shape >>> sequence_length = model._get_feat_extract_output_lengths(raw_sequence_length) >>> mask_time_indices = _compute_mask_indices((batch_size, sequence_length), mask_prob=0.2, mask_length=2) - >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.bool) + >>> mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.long) >>> with torch.no_grad(): ... outputs = model(input_values, mask_time_indices=mask_time_indices)