_is_peft_model update to recognise peft submodules, allowing training quantised models with peft submodules
Author: ambroser53
Pull request: yes

# What does this PR do?

Don't necessarily have peft models as the top-level wrapper for models, especially when working with custom built multi-modal models. For example:

```python
model = AutoModelForVision2Seq.from_pretrained(
  args.pretrained_ckpt,
  torch_dtype=compute_dtype,
  quantization_config=BitsAndBytesConfig(
      load_in_4bit=bits == 4,
      load_in_8bit=bits == 8,
      llm_int8_threshold=6.0,
      int8_quant_skip_modules=int8_quant_skip_modules,
      llm_int8_has_fp16_weight=False,
      bnb_4bit_compute_dtype=compute_dtype,
      bnb_4bit_use_double_quant=True,
      bnb_4bit_quant_type='nf4'  # {'fp4', 'nf4'}
  ) if bits < 16 else None,
  attn_implementation=args.attn_implementation,
)

if (args.use_lora and not resume_from_checkpoint and not ft_checkpoint_dir):
  target_modules = get_target_modules(model.model.text_model, args, bits)
  peft_config = LoraConfig(
      target_modules=target_modules,
      inference_mode=args.inference_mode,
      r=args.lora_r,
      lora_alpha=args.lora_alpha,
      lora_dropout=args.lora_dropout,
      use_dora=args.use_dora
  )
  model.model.text_model = get_peft_model(model.model.text_model, peft_config)

  if args.vit_train:
      target_modules = get_target_modules(model.model.vision_model, args, args.vit_bits, vit=True)
      peft_config = LoraConfig(
          target_modules=target_modules,
          inference_mode=args.inference_mode,
          r=args.vit_lora_r,
          lora_alpha=args.vit_lora_alpha,
          lora_dropout=args.lora_dropout,
          use_dora=args.use_dora_vit
      )
      model.model.vision_model = get_peft_model(model.model.vision_model, peft_config)

  if args.lora_abstractor:
      target_modules = get_target_modules(model.model.connector, args, args.bits)
      peft_config = LoraConfig(
          target_modules=target_modules,
          inference_mode=args.inference_mode,
          r=args.lora_r,
          lora_alpha=args.lora_alpha,
          lora_dropout=args.lora_dropout,
          use_dora=args.use_dora
      )
      model.model.connector = get_peft_model(model.model.connector, peft_config)
```

This allows the hf trainer to recognise such models as still being peft models and thereby allow quantised training (QLoRA).


Fixes #30878


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case. -> https://github.com/huggingface/transformers/issues/30878
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

@younesbelkada

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_30884). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@younesbelkada I've just done as you asked and it ran successfully but I have no working tree changes to commit.

Thanks ! Hmm I think something is off with our CI currently, let's wait for https://github.com/huggingface/transformers/pull/30932 being merged first

Is there any update on this? I'm still running the local version for training my model that uses this. Still don't understand why it couldn't be merged in the first place.

@ambroser53 It's still open as there's two outstanding comments/questions on the tests which were marked as resolved, but were not. In the first case, the comment needs to be updated, in the second, could you explain the intended behaviour? 

@amyeroberts I see where the confusion was here. I was under the assumption the code was fine and we were waiting on a fix for workflow checks (i.e. styling). I have changed the comments in the test to hopefully be more clear and expanded the it to run `trainer.train()` instead of just initialising the Trainer object and included a simple custom subclass with `save_pretrained` to allow it to work in that case to show the full use-case with training. 

Intended Behaviour: model is trainable when quantised with a peft sub-module.

Workflow tests are still failing so if there is actually anything I need to do there let me know.

@ambroser53 Great. For some of the failing tests re passing `trust_remote_code` for datasets, there's been upstream fixes. Could you rebase on main to include these? I think this should also fix a lot of the quality checks

@ambroser53 Apologies for the continued delay. Could you try rebasing again? This should resolve the timeout errors we're having on the CI 

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.