Skip to content

add freeze, unfreeze methods with experimental tag#15729

Open
nithinraok wants to merge 2 commits into
mainfrom
freeze-unfreeze-transformer-encoder
Open

add freeze, unfreeze methods with experimental tag#15729
nithinraok wants to merge 2 commits into
mainfrom
freeze-unfreeze-transformer-encoder

Conversation

@nithinraok
Copy link
Copy Markdown
Member

@nithinraok nithinraok commented May 25, 2026

What does this PR do ?

Add freeze() / unfreeze() methods to the ASR TransformerEncoder and mark the class as experimental.

Collection: ASR

Changelog

  • Add freeze() method to TransformerEncoder: sets requires_grad=False on all parameters and switches the module to eval mode.
  • Add unfreeze(partial: bool = False) method to TransformerEncoder: sets requires_grad=True on all parameters; switches to train mode unless partial=True.
  • Decorate TransformerEncoder with @experimental from nemo.utils.decorators to signal API stability is not yet guaranteed.

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

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

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

Signed-off-by: nithinraok <nithinrao.koluguri@gmail.com>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 25, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the ASR label May 25, 2026
@nithinraok
Copy link
Copy Markdown
Member Author

/ok to test 1fc31e0

@nithinraok
Copy link
Copy Markdown
Member Author

/claude review

Comment thread nemo/collections/asr/modules/transformer_encoder.py Outdated
Comment thread nemo/collections/asr/modules/transformer_encoder.py Outdated
Signed-off-by: nithinraok <nithinrao.koluguri@gmail.com>
x = x.transpose(1, 2) # (B, T, D) -> (B, D, T)
return x, length

def freeze(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nitpick but maybe this should be either a mixin, or a standalone module ModelFreezer or free function freeze(module) / unfreeze(module, partial)? the logic seems quite generic, not sure if it should be included in class definition. this class could just do

def freeze(self):
    return freeze(self)
def unfreeze(self, partial):
    return unfreeze(self, partial=partial)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah actually, It is part of NeuralModule but since we not inheriting I added these methods separately for now.

@pzelasko
Copy link
Copy Markdown
Collaborator

/ok to test e1f0bc4

@github-actions
Copy link
Copy Markdown
Contributor

[🤖]: Hi @nithinraok 👋,

We wanted to let you know that a CICD pipeline for this PR just finished successfully.

So it might be time to merge this PR or get some approvals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants