def _prepare_hf_model(
        model: HfModelHandler, device: str, torch_dtype: Optional[torch.dtype] = None
    ) -> HfModelHandler:
        """Prepare the HfModelHandler for conversion.

        This method handles the following cases:
        1. HfModelHandler with no load kwargs
            - no need to change the model
        2. HfModelHandler with load kwargs
            - update load_kwargs.torch_dtype if torch_dtype is specified
            - if torch_dtype not specified, make sure the load kwargs specify a dtype that is supported for
                conversion on the specified device
            - if quantization_method == "bitsandbytes" and load_in_4bit is True
                - remove quantization config from the load kwargs
                - find quantized modules and add them to the model attributes
                - the onnx model must be quantized using OnnxBnb4Quantization pass after conversion
        """
        from olive.common.hf.peft import is_peft_model

        if not model.load_kwargs:
            return model

        model_attributes = deepcopy(model.model_attributes or {})
        load_kwargs = model.load_kwargs
        model_dtype = load_kwargs.get_torch_dtype()
        new_load_kwargs = deepcopy(load_kwargs.dict())

        if torch_dtype and torch_dtype != model_dtype:
            # if the load kwargs specify a different dtype, update the load kwargs
            logger.debug(
                "Changing torch_dtype in load kwargs from %s to %s.",
                load_kwargs.get_torch_dtype(),
                torch_dtype,
            )
            new_load_kwargs["torch_dtype"] = torch_dtype
            model_attributes["torch_dtype"] = str(torch_dtype).replace("torch.", "")

        if load_kwargs.quantization_method == "bitsandbytes" and load_kwargs.quantization_config["load_in_4bit"]:
            logger.debug(
                "Bitsandbytes 4bit quantization is not supported for conversion. The quantization config is removed"
                " from the load kwargs. Use OnnxBnb4Quantization pass after conversion to quantize the"
                " model."
            )
            new_load_kwargs["quantization_method"] = None
            new_load_kwargs["quantization_config"] = None
            model_attributes["quantization_config"] = load_kwargs.quantization_config
            if "quantized_modules" not in model_attributes:
                # find and add quantized modules to the model attributes
                # the QLoRA pass already adds quantized_modules to the model attributes, so this will not be
                # executed if the model was generated by QLoRA
                quantized_model = model.load_model(cache_model=False)

                # if PeftModel, need to unload adapter before finding quantized modules
                if is_peft_model(quantized_model):
                    quantized_model = quantized_model.unload()

                import bitsandbytes as bnb

                model_attributes["quantized_modules"] = find_submodules(quantized_model, bnb.nn.Linear4bit)

        model_config = model.to_json()["config"]
        model_config["load_kwargs"] = new_load_kwargs
        model_config["model_attributes"] = model_attributes
        return HfModelHandler(**model_config)
Prepare the HfModelHandler for conversion.

        This method handles the following cases:
        1. HfModelHandler with no load kwargs
            - no need to change the model
        2. HfModelHandler with load kwargs
            - update load_kwargs.torch_dtype if torch_dtype is specified
            - if torch_dtype not specified, make sure the load kwargs specify a dtype that is supported for
                conversion on the specified device
            - if quantization_method == "bitsandbytes" and load_in_4bit is True
                - remove quantization config from the load kwargs
                - find quantized modules and add them to the model attributes
                - the onnx model must be quantized using OnnxBnb4Quantization pass after conversion
        
olive/passes/onnx/conversion.py