code: def create_and_prepare_model(args):
      compute_dtype = getattr(torch, args.bnb_4bit_compute_dtype)
  
      bnb_config = BitsAndBytesConfig(
          load_in_4bit=args.use_4bit,
          bnb_4bit_quant_type=args.bnb_4bit_quant_type,
          bnb_4bit_compute_dtype=compute_dtype,
          bnb_4bit_use_double_quant=args.use_nested_quant,
      )
  
      if compute_dtype == torch.float16 and args.use_4bit:
          major, _ = torch.cuda.get_device_capability()
          if major >= 8:
              print("=" * 80)
              print(
                  "Your GPU supports bfloat16, you can accelerate training with the arguments --bf16 --bnb_4bit_compute_dtype bfloat16"
              )
              print("=" * 80)
  
      model = AutoModelForCausalLM.from_pretrained(
          args.model_name,
          quantization_config=bnb_config,
          device_map="auto",
      )
  
      model.config.use_cache = False
      # https://github.com/huggingface/transformers/pull/24906
      model.config.pretraining_tp = 1
  
      tokenizer = AutoTokenizer.from_pretrained(
          args.model_name, trust_remote_code=True
      )
  
      tokenizer.pad_token = tokenizer.eos_token
      # Fix weird overflow issue with fp16 training
      tokenizer.padding_side = "right"
  
      return model, tokenizer
  
file_path: dstack/src/dstack/api/_public/huggingface/finetuning/sft/train.py
imports: from dataclasses import dataclass, field
  from typing import Optional, Union
  import torch
  from datasets import load_dataset
  from peft import LoraConfig, PeftModel
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, HfArgumentParser, TrainingArguments
  from trl import SFTTrainer
label_desc: Use image node_id 1 for calling a global function with example usage: create_and_prepare_model(args) and returns: model,  tokenizer