Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fairseq2/models/wav2vec2/asr/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def bib61_300m() -> Wav2Vec2AsrConfig:
@wav2vec2_asr_arch("300m_bib1143")
def bib1143_300m() -> Wav2Vec2AsrConfig:
config = bib61_300m()
config.vocab_info.size = 3335
config.vocab_info.size = 3292
Comment thread
artemru marked this conversation as resolved.
Outdated
return config

@wav2vec2_asr_arch("1b_bib61")
Expand Down
15 changes: 15 additions & 0 deletions src/fairseq2/nn/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,21 @@ def load_state_dict(
``state_dict`` does not contain any keys corresponding to descendants that are set to ``None``
via :meth:`Module.register_module()`.
"""
# Key mapping
Comment thread
artemru marked this conversation as resolved.
Outdated
need_mapping = False
sample_key = list(state_dict.keys())[0]
if (
sample_key.startswith("module.")
and not sample_key in module.state_dict().keys()
):
mapped_key = sample_key[7:]
if mapped_key in module.state_dict().keys():
need_mapping = True

if need_mapping:
key_mapping = lambda key: key[7:] if key.startswith("module.") else key
state_dict = {key_mapping(key): value for key, value in state_dict.items()}

module.load_state_dict(state_dict, strict=strict)

unexpected_keys = []
Expand Down
11 changes: 10 additions & 1 deletion src/fairseq2/recipes/asr/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from fairseq2.data.text.tokenizers import TextTokenDecoder, TextTokenizer
from fairseq2.gang import Gang
from fairseq2.metrics import Mean
from fairseq2.metrics.text import WerMetric
from fairseq2.metrics.text import BleuMetric, WerMetric
from fairseq2.models.asr import AsrModel, AsrModelOutput
from fairseq2.models.seq2seq import Seq2SeqBatch
from fairseq2.models.sequence import SequenceBatch
Expand Down Expand Up @@ -121,6 +121,8 @@ def __call__(
refs, ref_seqs, ref_padding_mask, hyps, hyp_seqs, hyp_padding_mask
)

metric_bag.bleu.update(refs, hyps)

try:
# Dump references.
stream = self._ref_output_stream
Expand Down Expand Up @@ -148,6 +150,7 @@ def __call__(
class AsrMetricBag(BaseMetricBag):
ctc_loss: Mean
wer: WerMetric
bleu: BleuMetric

def __init__(self, gang: Gang, train: bool = True) -> None:
super().__init__(gang, train=train)
Expand All @@ -158,6 +161,12 @@ def __init__(self, gang: Gang, train: bool = True) -> None:

self.register_metric("wer", WerMetric(device=self.device), persistent=False)

self.register_metric(
"bleu",
BleuMetric(tokenizer="flores200", device=self.device),
persistent=False,
)

@torch.inference_mode()
def update_ctc_loss(self, batch: Seq2SeqBatch, loss: Tensor) -> None:
n = batch.batch_size
Expand Down