Views
No views yet
adapter-transformers library aimed at enabling multilingual text generation. It leverages datasets such as siddeo99/sidtestfiverrmulti and supports multiple languages including English, Hindi, and Punjabi.1!pip install -q accelerate==0.21.0 peft==0.4.0 bitsandbytes==0.40.2 transformers==4.31.0 trl==0.4.7
2!pip install pyarrow1import os
2import torch
3from datasets import load_dataset
4from transformers import (
5 AutoModelForCausalLM,
6 AutoTokenizer,
7 BitsAndBytesConfig,
8 HfArgumentParser,
9 TrainingArguments,
10 pipeline,
11)
12from peft import LoraConfig, PeftModel1# The model that you want to train from the Hugging Face hub
2model_name = "siddeo99/job_search_category"
3
4################################################################################
5# QLoRA parameters
6################################################################################
7
8# LoRA attention dimension
9lora_r = 64
10
11# Alpha parameter for LoRA scaling
12lora_alpha = 16
13
14# Dropout probability for LoRA layers
15lora_dropout = 0.1
16
17################################################################################
18# bitsandbytes parameters
19################################################################################
20
21# Activate 4-bit precision base model loading
22use_4bit = True
23
24# Compute dtype for 4-bit base models
25bnb_4bit_compute_dtype = "float16"
26
27# Quantization type (fp4 or nf4)
28bnb_4bit_quant_type = "nf4"
29
30# Activate nested quantization for 4-bit base models (double quantization)
31use_nested_quant = False
32device_map = {"": 0}1# Load tokenizer and model with QLoRA configuration
2compute_dtype = getattr(torch, bnb_4bit_compute_dtype)
3
4bnb_config = BitsAndBytesConfig(
5 load_in_4bit=use_4bit,
6 bnb_4bit_quant_type=bnb_4bit_quant_type,
7 bnb_4bit_compute_dtype=compute_dtype,
8 bnb_4bit_use_double_quant=use_nested_quant,
9)
10# Check GPU compatibility with bfloat16
11if compute_dtype == torch.float16 and use_4bit:
12 major, _ = torch.cuda.get_device_capability()
13 if major >= 8:
14 print("=" * 80)
15 print("Your GPU supports bfloat16: accelerate training with bf16=True")
16 print("=" * 80)
17
18# Load base model
19model = AutoModelForCausalLM.from_pretrained(
20 model_name,
21 quantization_config=bnb_config,
22 device_map=device_map
23)
24model.config.use_cache = False
25model.config.pretraining_tp = 1
26
27# Load LLaMA tokenizer
28tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
29tokenizer.pad_token = tokenizer.eos_token
30tokenizer.padding_side = "right" # Fix weird overflow issue with fp16 training
31
32# Load LoRA configuration
33peft_config = LoraConfig(
34 lora_alpha=lora_alpha,
35 lora_dropout=lora_dropout,
36 r=lora_r,
37 bias="none",
38 task_type="CAUSAL_LM",
39)1prompt = "What is a large language model?"
2pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
3result = pipe(f"<s>[INST] {prompt} [/INST]")
4print(result[0]['generated_text'])1from transformers import (
2 AutoModelForCausalLM,
3 AutoTokenizer,
4 pipeline,
5)
6from peft import LoraConfig1model = AutoModelForCausalLM.from_pretrained(model_name)
2
3model.config.use_cache = False
4model.config.pretraining_tp = 1
5tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
6tokenizer.pad_token = tokenizer.eos_token
7tokenizer.padding_side = "right" # Fix weird overflow issue with fp16 training
8# Load LoRA configuration
9peft_config = LoraConfig(
10 lora_alpha=lora_alpha,
11 lora_dropout=lora_dropout,
12 r=lora_r,
13 bias="none",
14 task_type="CAUSAL_LM",
15)
16# Run text generation pipeline with our next model
17prompt = "भारत से ऑस्ट्रेलिया में एक कार्य वीजा के लिए आवेदन करने के लिए क्या आवश्यकताएं हैं?"
18pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
19result = pipe(f"<s>[INST] {prompt} [/INST]")
20print(result[0]['generated_text'])
21