added README.md
Browse files
README.md
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
base_model: meta-llama/Meta-Llama-3-70B-Instruct
|
4 |
+
model-index:
|
5 |
+
- name: Llama3-70b-4bit
|
6 |
+
results:
|
7 |
+
- task:
|
8 |
+
name: Text Generation
|
9 |
+
type: text-generation
|
10 |
+
metrics:
|
11 |
+
- name: Wer
|
12 |
+
type: wer
|
13 |
+
value: 4.446809768789546
|
14 |
+
pipeline_tag: text-generation
|
15 |
+
---
|
16 |
+
|
17 |
+
|
18 |
+
# Llama3-70b-4bit
|
19 |
+
|
20 |
+
This model is a quantized version of [meta-llama/Meta-Llama-3-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-70B-Instruct)
|
21 |
+
|
22 |
+
|
23 |
+
### Libraries to Install
|
24 |
+
|
25 |
+
- pip install transformers torch
|
26 |
+
|
27 |
+
### Authentication needed before running the script
|
28 |
+
|
29 |
+
Run the following command in the terminal/jupyter_notebook:
|
30 |
+
|
31 |
+
- Terminal: huggingface-cli login
|
32 |
+
- Jupyter_notebook:
|
33 |
+
|
34 |
+
```python
|
35 |
+
>>> from huggingface_hub import notebook_login
|
36 |
+
>>> notebook_login()
|
37 |
+
```
|
38 |
+
|
39 |
+
**NOTE:** Copy and Paste the token from your Huggingface Account Settings > Access Tokens > Create a new token / Copy the existing one.
|
40 |
+
|
41 |
+
|
42 |
+
### Script
|
43 |
+
|
44 |
+
```python
|
45 |
+
>>> from transformers import AutoTokenizer, AutoModelForCausalLM
|
46 |
+
>>> import torch
|
47 |
+
|
48 |
+
>>> # Load model and processor
|
49 |
+
>>> model_id = "screevoai/llama3-70b-4bit"
|
50 |
+
|
51 |
+
>>> # Load tokenizer and model
|
52 |
+
>>> tokenizer = AutoTokenizer.from_pretrained(model_id)
|
53 |
+
|
54 |
+
>>> model = AutoModelForCausalLM.from_pretrained(
|
55 |
+
>>> model_id,
|
56 |
+
>>> torch_dtype=torch.bfloat16,
|
57 |
+
>>> device_map="cuda:0"
|
58 |
+
>>> )
|
59 |
+
|
60 |
+
>>> # message
|
61 |
+
>>> messages = [
|
62 |
+
>>> {"role": "system", "content": "You are a personal assistant chatbot, so respond accordingly"},
|
63 |
+
>>> {"role": "user", "content": "What is Machine Learning?"},
|
64 |
+
>>> ]
|
65 |
+
|
66 |
+
>>> input_ids = tokenizer.apply_chat_template(
|
67 |
+
>>> messages,
|
68 |
+
>>> add_generation_prompt=True,
|
69 |
+
>>> return_tensors="pt"
|
70 |
+
>>> ).to(model.device)
|
71 |
+
|
72 |
+
>>> terminators = [
|
73 |
+
>>> tokenizer.eos_token_id,
|
74 |
+
>>> tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
75 |
+
>>> ]
|
76 |
+
|
77 |
+
>>> # Generate predictions using the model
|
78 |
+
>>> outputs = model.generate(
|
79 |
+
>>> input_ids,
|
80 |
+
>>> max_new_tokens=512,
|
81 |
+
>>> eos_token_id=terminators,
|
82 |
+
>>> do_sample=True,
|
83 |
+
>>> temperature=0.6,
|
84 |
+
>>> top_p=0.9,
|
85 |
+
>>> )
|
86 |
+
>>> response = outputs[0][input_ids.shape[-1]:]
|
87 |
+
|
88 |
+
>>> print(tokenizer.decode(response, skip_special_tokens=True))
|
89 |
+
|
90 |
+
```
|