File size: 3,112 Bytes
4efd8e6
 
ef234c1
 
 
 
 
 
8576c33
672f6fd
 
 
 
 
 
 
4efd8e6
f856306
 
 
 
 
 
 
6133670
 
 
f856306
 
 
 
8443345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4efd8e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef234c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
library_name: peft
datasets:
- b-mc2/sql-create-context
language:
- en
metrics:
- rouge
pipeline_tag: question-answering
license: apache-2.0
tags:
- SQL
- PEFT
- GPT
- GPT2-Medium
- Question& Answer
---

# GPT-2 Medium

## Model Details

**Model Description:** GPT-2 Medium is the **355M parameter** version of GPT-2, a transformer-based language model created and released by OpenAI. The model is a pretrained model on English language using a causal language modeling (CLM) objective. 

## Parameter-Efficient Fine-tuning (PEFT)

Parameter-Efficient Fine-tuning (PEFT) is a technique used to improve the performance of pre-trained language models (LLMs) on specific downstream tasks without fine-tuning all the model's parameters. This is done by freezing most of the model's parameters and only fine-tuning a small number of parameters that are specific to the downstream task.

## Training Data
the model is trained on 'b-mc2/sql-create-context' dataset upto 5000rows

## Usage:
please install `transformers`, and `peft`:
```
!pip install transformers peft
```
To use the model, you can run the following:

```py
import torch
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM,  AutoTokenizer

config = PeftConfig.from_pretrained("Naveengo/gpt2-medium-on-sql-create-context")
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=False)
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)


# Load the Lora model
model = PeftModel.from_pretrained(model,"Naveengo/gpt2-medium-on-sql-create-context")

from IPython.display import display, Markdown

def make_inference(question, context):
  batch = tokenizer(f"Below is an SQL instruction that describes a task, paired with an input that provides further context. Write an SQL query that appropriately completes the request using your expertise in SQL.  ### Instruction: {question}### Input: {context}### Response:", return_tensors='pt')
  
  with torch.cuda.amp.autocast():
    output_tokens = model.generate(**batch, max_new_tokens=100)

  display(Markdown((tokenizer.decode(output_tokens[0], skip_special_tokens=True))))  
#give question and context to function
make_inference(your_question_here, your_context_here)
```

## Training procedure


The following `bitsandbytes` quantization config was used during training:
- quant_method: bitsandbytes
- load_in_8bit: False
- load_in_4bit: True
- llm_int8_threshold: 6.0
- llm_int8_skip_modules: None
- llm_int8_enable_fp32_cpu_offload: False
- llm_int8_has_fp16_weight: False
- bnb_4bit_quant_type: nf4
- bnb_4bit_use_double_quant: True
- bnb_4bit_compute_dtype: float16

The following `bitsandbytes` quantization config was used during training:
- quant_method: bitsandbytes
- load_in_8bit: False
- load_in_4bit: True
- llm_int8_threshold: 6.0
- llm_int8_skip_modules: None
- llm_int8_enable_fp32_cpu_offload: False
- llm_int8_has_fp16_weight: False
- bnb_4bit_quant_type: nf4
- bnb_4bit_use_double_quant: True
- bnb_4bit_compute_dtype: float16
### Framework versions

- PEFT 0.5.0

- PEFT 0.5.0