dingckc commited on
Commit
ffc484c
·
verified ·
1 Parent(s): a4ad8e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -5,11 +5,13 @@ import torch
5
 
6
  import bitsandbytes as bnb
7
 
8
- # 設置模型 ID 和加載 Hugging Face API token
9
  model_id = "dingckc/FineLlama-3.1-8B"
10
- tokenizer = AutoTokenizer.from_pretrained(model_id, token=os.getenv('ACCESS_KEY'))
11
- model = AutoModelForCausalLM.from_pretrained(model_id, load_in_8bit=True, token=os.getenv('ACCESS_KEY'))
12
- model = model.to("cuda" if torch.cuda.is_available() else "cpu")
 
 
 
13
 
14
  # 定義推理函數
15
  def evaluate_essay(title, essay):
 
5
 
6
  import bitsandbytes as bnb
7
 
 
8
  model_id = "dingckc/FineLlama-3.1-8B"
9
+ tokenizer = AutoTokenizer.from_pretrained(model_id, token=os.getenv("ACCESS_KEY"))
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ model_id,
12
+ device_map="auto", # 自動映射到可用設備(CPU)
13
+ torch_dtype=torch.float16 # 減少內存占用
14
+ )
15
 
16
  # 定義推理函數
17
  def evaluate_essay(title, essay):