Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import os
|
2 |
import torch
|
3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
import gradio as gr
|
5 |
import spaces
|
6 |
|
@@ -23,24 +23,17 @@ class LlamaGuardModeration:
|
|
23 |
def initialize_model(self):
|
24 |
"""モデルとトークナイザーの初期化"""
|
25 |
if self.model is None:
|
26 |
-
# quantization_configの設定
|
27 |
-
quantization_config = BitsAndBytesConfig(
|
28 |
-
load_in_8bit=True,
|
29 |
-
bnb_4bit_compute_dtype=self.dtype
|
30 |
-
)
|
31 |
-
|
32 |
# トークナイザーの初期化
|
33 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
34 |
self.model_id,
|
35 |
token=self.huggingface_token
|
36 |
)
|
37 |
|
38 |
-
#
|
39 |
self.model = AutoModelForCausalLM.from_pretrained(
|
40 |
self.model_id,
|
41 |
torch_dtype=self.dtype,
|
42 |
device_map="auto",
|
43 |
-
quantization_config=quantization_config,
|
44 |
token=self.huggingface_token,
|
45 |
low_cpu_mem_usage=True
|
46 |
)
|
|
|
1 |
import os
|
2 |
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
import gradio as gr
|
5 |
import spaces
|
6 |
|
|
|
23 |
def initialize_model(self):
|
24 |
"""モデルとトークナイザーの初期化"""
|
25 |
if self.model is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# トークナイザーの初期化
|
27 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
28 |
self.model_id,
|
29 |
token=self.huggingface_token
|
30 |
)
|
31 |
|
32 |
+
# モデルの初期化(bitsandbytesなし)
|
33 |
self.model = AutoModelForCausalLM.from_pretrained(
|
34 |
self.model_id,
|
35 |
torch_dtype=self.dtype,
|
36 |
device_map="auto",
|
|
|
37 |
token=self.huggingface_token,
|
38 |
low_cpu_mem_usage=True
|
39 |
)
|