code: def training_function(args):
      # set seed
      set_seed(args.seed)
  
      dataset = load_from_disk(args.dataset_path)
      # load model from the hub
      model = AutoModelForCausalLM.from_pretrained(
          args.model_id,
          use_cache=False
          if args.gradient_checkpointing
          else True,  # this is needed for gradient checkpointing
          device_map="auto",
          load_in_8bit=True,
      )
      # create peft config
      model = create_peft_config(model)
  
      # Define training args
      output_dir = "/tmp"
      training_args = TrainingArguments(
          output_dir=output_dir,
          overwrite_output_dir=True,
          per_device_train_batch_size=args.per_device_train_batch_size,
          bf16=args.bf16,  # Use BF16 if available
          learning_rate=args.lr,
          num_train_epochs=args.epochs,
          gradient_checkpointing=args.gradient_checkpointing,
          gradient_accumulation_steps=2,
          # logging strategies
          logging_dir=f"{output_dir}/logs",
          logging_strategy="steps",
          logging_steps=10,
          save_strategy="no",
          optim="adafactor",
      )
  
      # Create Trainer instance
      trainer = Trainer(
          model=model,
          args=training_args,
          train_dataset=dataset,
          data_collator=default_data_collator,
      )
  
      # Start training
      trainer.train()
  
      # merge adapter weights with base model and save
      # save int 8 model
      trainer.model.save_pretrained(output_dir)
      # clear memory
      del model
      del trainer
      # load PEFT model in fp16
      peft_config = PeftConfig.from_pretrained(output_dir)
      model = AutoModelForCausalLM.from_pretrained(
          peft_config.base_model_name_or_path,
          return_dict=True,
          torch_dtype=torch.float16,
          low_cpu_mem_usage=True,
      )
      model = PeftModel.from_pretrained(model, output_dir)
      model.eval()
      # Merge LoRA and base model and save
      merged_model = model.merge_and_unload()
      merged_model.save_pretrained("/opt/ml/model/")
  
      # save tokenizer for easy inference
      tokenizer = AutoTokenizer.from_pretrained(args.model_id)
      tokenizer.save_pretrained("/opt/ml/model/")
  
      # copy inference script
      os.makedirs("/opt/ml/model/code", exist_ok=True)
      shutil.copyfile(
          os.path.join(os.path.dirname(__file__), "inference.py"),
          "/opt/ml/model/code/inference.py",
      )
      shutil.copyfile(
          os.path.join(os.path.dirname(__file__), "requirements.txt"),
          "/opt/ml/model/code/requirements.txt",
      )
  
file_path: hf-notebooks/sagemaker/24_train_bloom_peft_lora/scripts/run_clm.py
imports: import os
  import argparse
  from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed, default_data_collator
  from datasets import load_from_disk
  import torch
  from transformers import Trainer, TrainingArguments
  from peft import PeftConfig, PeftModel
  import shutil
label_desc: Use image node_id 3 for calling a global function with example usage: training_function(args) without return types