Updated model card
Browse files
README.md
CHANGED
|
@@ -20,45 +20,53 @@ Make sure you have the following dependencies installed:
|
|
| 20 |
You can install the required packages using pip:
|
| 21 |
|
| 22 |
```bash
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
```
|
| 25 |
|
| 26 |
```py
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
model_id,
|
|
|
|
|
|
|
|
|
|
| 36 |
quantization_config=bnb_config,
|
| 37 |
-
device_map=
|
| 38 |
)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# Load tokenizer
|
| 43 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 44 |
tokenizer.pad_token = tokenizer.eos_token
|
| 45 |
-
tokenizer.padding_side = "right" # Fix weird overflow issue with fp16 training
|
| 46 |
```
|
| 47 |
|
| 48 |
```py
|
| 49 |
-
# Ignore warnings
|
| 50 |
-
logging.set_verbosity(logging.CRITICAL)
|
| 51 |
-
|
| 52 |
# Run text generation pipeline with our next model
|
| 53 |
-
system_prompt =
|
| 54 |
-
prompt =
|
| 55 |
|
| 56 |
pipe = pipeline(
|
| 57 |
task="text-generation",
|
| 58 |
-
model=
|
| 59 |
tokenizer=tokenizer,
|
| 60 |
max_new_tokens=128, # Increase this to allow for longer outputs
|
| 61 |
-
temperature=0.
|
| 62 |
top_k=50, # Limits to the top 50 tokens
|
| 63 |
do_sample=True, # Enables sampling
|
| 64 |
return_full_text=True
|
|
@@ -67,11 +75,5 @@ pipe = pipeline(
|
|
| 67 |
result = pipe(f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>")
|
| 68 |
# print(result[0]['generated_text'])
|
| 69 |
generated_text = result[0]['generated_text']
|
| 70 |
-
|
| 71 |
-
# Remove the leading system prompt and special tokens
|
| 72 |
-
# start_idx = generated_text.find("[/INST]") + len("[/INST]")
|
| 73 |
-
# response_text = generated_text[start_idx:].strip() # Get text after [/INST]
|
| 74 |
-
|
| 75 |
-
# Print the extracted response text
|
| 76 |
print(generated_text)
|
| 77 |
```
|
|
|
|
| 20 |
You can install the required packages using pip:
|
| 21 |
|
| 22 |
```bash
|
| 23 |
+
!git clone https://github.com/huggingface/transformers.git
|
| 24 |
+
%cd transformers
|
| 25 |
+
!git checkout <commit_id_for_4.47.0.dev0>
|
| 26 |
+
!pip install .
|
| 27 |
+
!pip install -q accelerate==0.34.2 bitsandbytes==0.44.1 peft==0.13.1
|
| 28 |
+
|
| 29 |
```
|
| 30 |
|
| 31 |
```py
|
| 32 |
+
# quantization of model
|
| 33 |
+
bnb_config = BitsAndBytesConfig(
|
| 34 |
+
load_in_4bit=True,
|
| 35 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
| 36 |
+
bnb_4bit_use_double_quant=True,
|
| 37 |
+
bnb_4bit_quant_type='nf4'
|
| 38 |
+
)
|
| 39 |
+
```
|
| 40 |
|
| 41 |
+
```py
|
| 42 |
+
# Load model & tokenizer
|
| 43 |
+
model_id = "Ahanaas/Hermes-3-Llama-3.1-8B_finetune_prashu"
|
| 44 |
|
| 45 |
+
from transformers import AutoTokenizer, LlamaTokenizer, PreTrainedTokenizerFast
|
| 46 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 47 |
model_id,
|
| 48 |
+
low_cpu_mem_usage=True,
|
| 49 |
+
return_dict=True,
|
| 50 |
+
torch_dtype=torch.float16,
|
| 51 |
quantization_config=bnb_config,
|
| 52 |
+
device_map=0,
|
| 53 |
)
|
| 54 |
+
# Tokenizer
|
| 55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, padding_side="right", use_fast=False)
|
|
|
|
|
|
|
|
|
|
| 56 |
tokenizer.pad_token = tokenizer.eos_token
|
|
|
|
| 57 |
```
|
| 58 |
|
| 59 |
```py
|
|
|
|
|
|
|
|
|
|
| 60 |
# Run text generation pipeline with our next model
|
| 61 |
+
system_prompt = ''''''
|
| 62 |
+
prompt = ''''''
|
| 63 |
|
| 64 |
pipe = pipeline(
|
| 65 |
task="text-generation",
|
| 66 |
+
model=base_model,
|
| 67 |
tokenizer=tokenizer,
|
| 68 |
max_new_tokens=128, # Increase this to allow for longer outputs
|
| 69 |
+
temperature=0.4, # Encourages more varied outputs
|
| 70 |
top_k=50, # Limits to the top 50 tokens
|
| 71 |
do_sample=True, # Enables sampling
|
| 72 |
return_full_text=True
|
|
|
|
| 75 |
result = pipe(f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>")
|
| 76 |
# print(result[0]['generated_text'])
|
| 77 |
generated_text = result[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
print(generated_text)
|
| 79 |
```
|