Shortcuts

disable_adapter

torchtune.modules.peft.disable_adapter(model: Module) Generator[None, None, None][source]

Temporarily disable the adapters in a neural network model. This can be used, for example, in DPO for treating the lora adapters as the policy model and disabling it to treat the base model as the reference model.

This context manager goes through all modules in the provided neural network model, and if a module has an ‘adapter_params’ attribute that is callable and a ‘disabled’ attribute, it sets ‘disabled’ to True. Then, the control is given back to caller. Once that finalizes, it sets ‘disabled’ back to False for all modules that were temporarily disabled.

Parameters:

model (nn.Module) – The neural network model whose adapters are to be temporarily disabled.

Yields:

None – This function yields control back to the caller, with the adapters disabled.

Example

>>> with disable_adapter(model):
...     # Perform operations with adapters disabled
...     pass

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources