File size: 1,574 Bytes
4934002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380ced9
4934002
 
7d78035
 
 
 
 
4934002
346645d
8ec9a4f
 
 
 
 
 
 
346645d
8ec9a4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380ced9
8ec9a4f
 
4934002
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
---
library_name: transformers
tags: []
---

# Model Card for Model ID

<!-- Provide a quick summary of what the model is/does. -->



## Model Details


<!-- Provide a longer summary of what this model is. -->

This is the model card of a Phi-2 model trained on a synthetic data set to solve step by guid to solve a riddle or answer any kind of question
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->

### Requiremnts
```python
!pip install -U transformers bitsandbytes einops accelerate peft datasets wandb
```

### Direct Use
```python
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig, set_seed

# set seed
set_seed(42)

# Load model

modelpath = "DisgustingOzil/phi-2-riddler"
model = AutoModelForCausalLM.from_pretrained(
    modelpath,
    device_map="auto",
    quantization_config=BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_compute_dtype=torch.float16,
        bnb_4bit_quant_type="nf4",
    ),
    torch_dtype=torch.float16,
)
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(modelpath, use_fast=False)
question = "Why life is so difficult of life?"
messages = [
    {"role": "user", "content": question},
]
        
input_tokens = tokenizer.apply_chat_template(
    messages, 
    add_generation_prompt=True,
    return_tensors="pt"
).to("cuda")
output_tokens = model.generate(input_tokens, max_new_tokens=200)
output = tokenizer.decode(output_tokens[0])

print(output)
```