def state_dict(self,
                   *args,
                   destination=None,
                   prefix='',
                   keep_vars=False,
                   adapter_name: str = None,
                   peft_format: bool = False,
                   **kwargs):
        """
        Args:
            destination (`dict`, `optional`): If provided, the state of module will
                be updated into the dict and the same object is returned.
                Otherwise, an ``OrderedDict`` will be created and returned.
                Default: ``None``.
            prefix (`str`, `optional`): a prefix added to parameter and buffer
                names to compose the keys in state_dict. Default: ``''``.
            keep_vars (`bool`, `optional`): by default the :class:`~torch.Tensor` s
                returned in the state dict are detached from autograd. If it's
                set to ``True``, detaching will not be performed.
                Default: ``False``.
            adapter_name (`str`, `optional`): The name of the adapter's parameters to be saved,
                `None` input will save all adapters.
            peft_format (`bool`, `optional`): Save with peft format (extra `base_model.model.` prefix)
            **kwargs:
                save_adapter(`bool`): Save adapters or not, default True
                save_extra_states(`bool`): Save extra states or not, default True
        Returns:
            The state dict to be saved.
        """
        state_dict = kwargs.get('state_dict')
        if state_dict is None:
            state_dict = self.base_model.state_dict(destination=destination, prefix=prefix, keep_vars=keep_vars)
        state_dict = {
            key[len('base_model.'):] if key.startswith('base_model.') else key: value
            for key, value in state_dict.items()
        }
        if not self.has_additional_modules:
            return state_dict

        state_dicts = {}
        if kwargs.get('save_adapter', True):
            for name, output in self.adapters.items():
                if (adapter_name == name or adapter_name is None) and output.config.has_additional_modules:  # noqa
                    state_dicts.update(output.state_dict_callback(state_dict, name))
                    modules_to_save_names = [
                        sub_name for sub_name, _ in self.base_model.named_parameters()
                        if f'modules_to_save.{name}' in sub_name
                    ]
                    for module_name in modules_to_save_names:
                        if f'modules_to_save.{name}' in module_name:
                            state_dicts[module_name.replace(f'modules_to_save.{name}.', '')] = state_dict[module_name]
        if kwargs.get('save_extra_states', True):
            state_dicts.update({
                k: v
                for k, v in state_dict.items() if any(
                    re.fullmatch(extra_key, k) for extra_key in self.extra_state_keys)
            })
        if peft_format:
            new_state_dict = {}
            for key, value in state_dicts.items():
                if not key.startswith('base_model.model.'):
                    key = 'base_model.model.' + key
                key = key.replace(f'lora_A.{adapter_name}.', 'lora_A.')
                key = key.replace(f'lora_B.{adapter_name}.', 'lora_B.')
                key = key.replace(f'lora_embedding_A.{adapter_name}.', 'lora_embedding_A.')
                key = key.replace(f'lora_embedding_B.{adapter_name}.', 'lora_embedding_B.')
                new_state_dict[key] = value
            state_dicts = new_state_dict
        return state_dicts

        Args:
            destination (`dict`, `optional`): If provided, the state of module will
                be updated into the dict and the same object is returned.
                Otherwise, an ``OrderedDict`` will be created and returned.
                Default: ``None``.
            prefix (`str`, `optional`): a prefix added to parameter and buffer
                names to compose the keys in state_dict. Default: ``''``.
            keep_vars (`bool`, `optional`): by default the :class:`~torch.Tensor` s
                returned in the state dict are detached from autograd. If it's
                set to ``True``, detaching will not be performed.
                Default: ``False``.
            adapter_name (`str`, `optional`): The name of the adapter's parameters to be saved,
                `None` input will save all adapters.
            peft_format (`bool`, `optional`): Save with peft format (extra `base_model.model.` prefix)
            **kwargs:
                save_adapter(`bool`): Save adapters or not, default True
                save_extra_states(`bool`): Save extra states or not, default True
        Returns:
            The state dict to be saved.
        
swift/tuners/base.py