stuser2023
commited on
Commit
•
673a1b8
1
Parent(s):
c4883b1
Update README.md
Browse files
README.md
CHANGED
@@ -37,22 +37,20 @@ lora_r = 8
|
|
37 |
|
38 |
```python
|
39 |
import torch
|
40 |
-
from transformers import AutoTokenizer,
|
41 |
-
from peft import PeftModel,PeftConfig
|
42 |
|
43 |
-
|
44 |
-
|
|
|
45 |
|
46 |
model = AutoModelForCausalLM.from_pretrained(
|
47 |
-
|
48 |
-
|
49 |
device_map={'': 0}, # 設定使用的設備,此處指定為 GPU 0
|
50 |
trust_remote_code=True,
|
51 |
)
|
52 |
model.config.use_cache = False
|
53 |
-
|
54 |
-
model = PeftModel.from_pretrained(model, finetune_model_path, device_map={"": 0})
|
55 |
-
model =model.eval()
|
56 |
```
|
57 |
|
58 |
**3.進行推論(文字生成)**
|
|
|
37 |
|
38 |
```python
|
39 |
import torch
|
40 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
|
|
41 |
|
42 |
+
model_name = "stuser2023/Llama2-7b-finetuned"
|
43 |
+
|
44 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
45 |
|
46 |
model = AutoModelForCausalLM.from_pretrained(
|
47 |
+
model_name,
|
48 |
+
quantization_config=quantization_config,
|
49 |
device_map={'': 0}, # 設定使用的設備,此處指定為 GPU 0
|
50 |
trust_remote_code=True,
|
51 |
)
|
52 |
model.config.use_cache = False
|
53 |
+
model=model.eval() #把Dropout功能關掉
|
|
|
|
|
54 |
```
|
55 |
|
56 |
**3.進行推論(文字生成)**
|