def save_pretrained(self,
                        save_directory: str,
                        safe_serialization: bool = False,
                        adapter_name: Union[str, List[str]] = None,
                        **kwargs):
        """Save the adapters to a local directory.

        Args:
            save_directory (`str`): The directory to use.
            safe_serialization (`bool`): Use safe tensors to save the weights, default False.
            adapter_name(`Union[str, List[str]]`): The adapters to be saved, default is `None` to save all.
        """
        peft_format = kwargs.pop('peft_format', False)
        if os.path.isfile(save_directory):
            raise ValueError(f'Provided path ({save_directory}) should be a directory, not a file')
        os.makedirs(save_directory, exist_ok=True)
        if not self.has_additional_modules:
            if hasattr(self.base_model, 'save_pretrained'):
                self.base_model.save_pretrained(save_directory, safe_serialization=safe_serialization)
            else:
                self._save_state_dict(self.base_model.state_dict(), save_directory, safe_serialization)
                self.create_or_update_model_card(save_directory)
        else:
            self.create_or_update_model_card(save_directory)

        adapter_names = adapter_name if isinstance(adapter_name, list) or adapter_name is None else [adapter_name]

        state_dict_kwargs = {}
        state_dict = kwargs.get('state_dict')
        if state_dict is not None:
            state_dict_kwargs['state_dict'] = kwargs['state_dict']
        for adapter_name, output in self.adapters.items():
            if adapter_names is not None and adapter_name not in adapter_names:
                continue

            save_to_peft = peft_format and output.config.swift_type == SwiftTuners.LORA
            save_to_peft = save_to_peft and output.config.can_be_saved_to_peft()
            if peft_format and not save_to_peft:
                logger.error('You are using additional lora parameters, which is not compatible with peft,'
                             'which is unable to save to peft format.')
            output_dir = os.path.join(save_directory,
                                      adapter_name) if adapter_name != 'default' or not save_to_peft else save_directory

            if save_to_peft:
                config = output.config.to_peft_config()
                config.save_pretrained(output_dir)
            else:
                output.config.save_pretrained(output_dir)

            if output.save_callback:
                output.save_callback(self, output_dir, adapter_name)
                continue

            # save only the trainable weights
            output_state_dict = self.state_dict(
                adapter_name=adapter_name, save_extra_states=False, peft_format=save_to_peft, **state_dict_kwargs)
            os.makedirs(output_dir, exist_ok=True)
            if output_state_dict and output.config.has_additional_modules:
                self._save_state_dict(output_state_dict, output_dir, safe_serialization)

        output_state_dict = self.state_dict(save_extra_states=True, save_adapter=False, **state_dict_kwargs)
        if len(output_state_dict) > 0:
            if self.has_additional_modules:
                os.makedirs(os.path.join(save_directory, self.EXTRA_STATE_DIR), exist_ok=True)
                self._save_state_dict(output_state_dict, os.path.join(save_directory, self.EXTRA_STATE_DIR),
                                      safe_serialization)
                with open(
                        os.path.join(save_directory, self.EXTRA_STATE_DIR, CONFIG_NAME), 'w', encoding='utf-8') as file:
                    json.dump({'extra_state_keys': self.extra_state_keys}, file)
            else:
                logger.error('Full parameter training, save_extra_states will be ignored')

        if not os.path.exists(os.path.join(save_directory, 'configuration.json')):
            with open(os.path.join(save_directory, 'configuration.json'), 'w', encoding='utf-8') as f:
                f.write('{}')
Save the adapters to a local directory.

        Args:
            save_directory (`str`): The directory to use.
            safe_serialization (`bool`): Use safe tensors to save the weights, default False.
            adapter_name(`Union[str, List[str]]`): The adapters to be saved, default is `None` to save all.
        
swift/tuners/base.py