Spaces:
Paused
Paused
truongghieu
commited on
Commit
•
3ee1657
1
Parent(s):
4db03af
Update app.py
Browse files
app.py
CHANGED
@@ -6,14 +6,17 @@ import torch
|
|
6 |
# Check if a GPU is available
|
7 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
|
|
|
9 |
bnb_config = BitsAndBytesConfig(
|
10 |
load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype="float16", bnb_4bit_use_double_quant=True
|
11 |
)
|
12 |
|
13 |
|
14 |
tokenizer = AutoTokenizer.from_pretrained("truongghieu/deci-finetuned", trust_remote_code=True)
|
15 |
-
model
|
|
|
16 |
|
|
|
17 |
# Move the model to the GPU if available
|
18 |
|
19 |
generation_config = GenerationConfig(
|
@@ -31,7 +34,7 @@ generation_config = GenerationConfig(
|
|
31 |
# Define a function that takes a text input and generates a text output
|
32 |
def generate_text(text):
|
33 |
input_text = text
|
34 |
-
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
35 |
output_ids = model.generate(input_ids, generation_config=generation_config)
|
36 |
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
37 |
return output_text
|
|
|
6 |
# Check if a GPU is available
|
7 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
|
9 |
+
# Just for GPU
|
10 |
bnb_config = BitsAndBytesConfig(
|
11 |
load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype="float16", bnb_4bit_use_double_quant=True
|
12 |
)
|
13 |
|
14 |
|
15 |
tokenizer = AutoTokenizer.from_pretrained("truongghieu/deci-finetuned", trust_remote_code=True)
|
16 |
+
# Load model in this way if use GPU
|
17 |
+
# model = AutoModelForCausalLM.from_pretrained("truongghieu/deci-finetuned", trust_remote_code=True, quantization_config=bnb_config)
|
18 |
|
19 |
+
model = AutoModelForCausalLM.from_pretrained("truongghieu/deci-finetuned", trust_remote_code=True)
|
20 |
# Move the model to the GPU if available
|
21 |
|
22 |
generation_config = GenerationConfig(
|
|
|
34 |
# Define a function that takes a text input and generates a text output
|
35 |
def generate_text(text):
|
36 |
input_text = text
|
37 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
38 |
output_ids = model.generate(input_ids, generation_config=generation_config)
|
39 |
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
40 |
return output_text
|