def enable_lora(
        self,
        model: "PreTrainedModel",
        config: type[BasePassConfig],
        task: Optional[str] = None,
        use_dora: bool = False,
        adapter_path: Optional[str] = None,
    ) -> "PeftModel":
        """Enable LoRA fine-tuning on a Hugging Face PyTorch model.

        Add padding token to tokenizer and resize model embedding layer if needed.
        Prepare model for fine-tuning by freezing master weights and enabling gradient checkpointing if needed.
        Load or initialize LoRA adapters.

        :param model: The Hugging Face PyTorch model to enable LoRA fine-tuning on.
        :param config: The config for the pass run.
        :param task: The task type of the model.
        :param use_dora: Whether to use DoRA to train adapters.
        :param adapter_path: Path to the adapter weights. If None, will initialize new adapters.
        :return: The LoRA model.
        """
        logger.debug("Enabling LoRA fine-tuning")
        prepare_model_for_finetuning(model, config.training_args)

        # set model_parallel and is_parallelizable to True
        # we are using "auto" device_map, so model_parallel is True or doing DDP
        # don't want the trainer to do Data Parallel
        model.model_parallel = True
        model.is_parallelizable = True
        # TODO(team): ERROR: forward() got an unexpected keyword argument 'num_items_in_batch'
        # Temporary fix by disabling loss kwargs
        # https://github.com/huggingface/transformers/issues/35838
        model.accepts_loss_kwargs = False

        if not adapter_path:
            logger.debug("Initializing LoRA adapters from config")
            lora_model = self.init_adapters(model, config, task=task, use_dora=use_dora)
        else:
            from peft import PeftModel

            logger.debug("Loading LoRA adapters from %s", adapter_path)
            lora_model = PeftModel.from_pretrained(model, adapter_path, is_trainable=True)
        logger.debug("The number of trainable parameters in the LoRA model: %s", count_trainable_parameters(lora_model))
        # no need to cast lora modules to model's dtype, we dont do peft.prepare_model_for_kbit_training so the modules
        # are already in the same dtype as the model
        # casting to dtype is risky since for awq quant linear, it also casts the scales to dtype and but the qlinear
        # expects scales to be in half
        return lora_model
Enable LoRA fine-tuning on a Hugging Face PyTorch model.

        Add padding token to tokenizer and resize model embedding layer if needed.
        Prepare model for fine-tuning by freezing master weights and enabling gradient checkpointing if needed.
        Load or initialize LoRA adapters.

        :param model: The Hugging Face PyTorch model to enable LoRA fine-tuning on.
        :param config: The config for the pass run.
        :param task: The task type of the model.
        :param use_dora: Whether to use DoRA to train adapters.
        :param adapter_path: Path to the adapter weights. If None, will initialize new adapters.
        :return: The LoRA model.
        
olive/passes/pytorch/lora.py