Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mAES algorithm with patches #4662

Merged
merged 2 commits into from
Aug 3, 2022
Merged

Conversation

titu1994
Copy link
Collaborator

@titu1994 titu1994 commented Aug 2, 2022

What does this PR do ?

Adds the fixes from espnet/espnet#4312 for mAES RNNT beam search.

Collection: [ASR]

Changelog

  • Add deduplication checks
  • Improve speed of mAES beam search

Usage

# Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytorch_lightning as pl
from omegaconf import OmegaConf, open_dict

from nemo.collections.asr.models import EncDecRNNTBPEModel

def main():

    trainer = pl.Trainer(gpus=[1], precision=16, logger=False)

    # Model
    # path = 'some model path'

    asr_model = EncDecRNNTBPEModel.restore_from(path, trainer=trainer, map_location='cpu')

    asr_model.eval()
    asr_model.freeze()

    asr_model.preprocessor.featurizer.dither = 0.0
    asr_model.preprocessor.featurizer.pad_to = 0

    cfg = asr_model.cfg

    test_cfg = cfg.test_ds
    test_cfg.manifest_filepath = "manifests/test_other.json"
    test_cfg.batch_size = 256

    asr_model.setup_multiple_test_data(test_cfg)

    decoding_cfg = cfg.decoding

    with open_dict(decoding_cfg):
        decoding_cfg.strategy = "maes"
        decoding_cfg.fused_batch_size = -1
        decoding_cfg.beam.beam_size = 4
        decoding_cfg.beam.tsd_max_sym_exp = 10
        decoding_cfg.beam.alsd_max_target_len = 2.5
        decoding_cfg.beam.maes_num_steps = 2
        decoding_cfg.beam.maes_prefix_alpha = 1
        decoding_cfg.beam.maes_expansion_beta = 2
        decoding_cfg.beam.maes_expansion_gamma = 2.3

    asr_model.change_decoding_strategy(decoding_cfg)

    if asr_model.prepare_test(trainer):
        trainer.test(asr_model)


if __name__ == '__main__':
    main()

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

Signed-off-by: smajumdar <titu1994@gmail.com>
Signed-off-by: smajumdar <smajumdar@nvidia.com>
@titu1994 titu1994 requested a review from VahidooX August 2, 2022 21:44
Copy link
Collaborator

@VahidooX VahidooX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a minor comment.

pass

list_exp.append(new_hyp)
# new_hyp.y_sequence.append(int(k))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we drop this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i kinda kept it cause i might need it for debugging during rnnt beam setup

@titu1994 titu1994 merged commit 498ff20 into NVIDIA:main Aug 3, 2022
@titu1994 titu1994 deleted the fix_maes branch August 3, 2022 01:47
Davood-M pushed a commit to Davood-M/NeMo that referenced this pull request Aug 9, 2022
* First draft implementation fix of maes

Signed-off-by: smajumdar <titu1994@gmail.com>

* add deduplication checks

Signed-off-by: smajumdar <smajumdar@nvidia.com>
Signed-off-by: David Mosallanezhad <dmosallanezh@nvidia.com>
piraka9011 pushed a commit to piraka9011/NeMo that referenced this pull request Aug 25, 2022
* First draft implementation fix of maes

Signed-off-by: smajumdar <titu1994@gmail.com>

* add deduplication checks

Signed-off-by: smajumdar <smajumdar@nvidia.com>
Signed-off-by: Anas Abou Allaban <aabouallaban@pm.me>
hainan-xv pushed a commit to hainan-xv/NeMo that referenced this pull request Nov 29, 2022
* First draft implementation fix of maes

Signed-off-by: smajumdar <titu1994@gmail.com>

* add deduplication checks

Signed-off-by: smajumdar <smajumdar@nvidia.com>
Signed-off-by: Hainan Xu <hainanx@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants