code: def create_datasets(tokenizer, args):
      dataset = load_dataset(
          args.dataset_name,
          data_dir=args.subset,
          split=args.split,
          use_auth_token=True,
          num_proc=args.num_workers if not args.streaming else None,
          streaming=args.streaming,
      )
      if args.streaming:
          print("Loading the dataset in streaming mode")
          valid_data = dataset.take(args.size_valid_set)
          train_data = dataset.skip(args.size_valid_set)
          train_data = train_data.shuffle(
              buffer_size=args.shuffle_buffer, seed=None
          )
      else:
          dataset = dataset.train_test_split(test_size=0.005, seed=None)
          train_data = dataset["train"]
          valid_data = dataset["test"]
          print(
              f"Size of the train set: {len(train_data)}. Size of the validation set: {len(valid_data)}"
          )
  
      chars_per_token = chars_token_ratio(train_data, tokenizer)
      print(
          f"The character to token ratio of the dataset is: {chars_per_token:.2f}"
      )
  
      train_dataset = ConstantLengthDataset(
          tokenizer,
          train_data,
          formatting_func=prepare_sample_text,
          infinite=True,
          seq_length=args.seq_length,
          chars_per_token=chars_per_token,
      )
      valid_dataset = ConstantLengthDataset(
          tokenizer,
          valid_data,
          formatting_func=prepare_sample_text,
          infinite=False,
          seq_length=args.seq_length,
          chars_per_token=chars_per_token,
      )
      return train_dataset, valid_dataset
  
file_path: trl/examples/research_projects/stack_llama_2/scripts/sft_llama2.py
imports: import os
  from dataclasses import dataclass, field
  from typing import Optional
  import torch
  from accelerate import Accelerator
  from datasets import load_dataset
  from peft import AutoPeftModelForCausalLM, LoraConfig
  from tqdm import tqdm
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, HfArgumentParser, TrainingArguments
  from trl import SFTTrainer
  from trl.import_utils import is_npu_available, is_xpu_available
  from trl.trainer import ConstantLengthDataset
label_desc: Use image node_id 4 for calling a global function with example usage: create_datasets(tokenizer, args) and returns: train_dataset,  valid_dataset