disable_adapter¶
- torchtune.modules.peft.disable_adapter(model: Module) Generator[None, None, None] [source]¶
Temporarily disable the adapters in a model. For example, this can be used 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 adisabled
attribute, it setsdisabled
to True. Then, the control is given back to caller. When exiting the context manager, it setsdisabled
back to False for all modules that were temporarily disabled.- Parameters:
model (nn.Module) – The 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