souzat19 commited on
Commit
d26b0a2
·
verified ·
1 Parent(s): a670346

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +8 -2
handler.py CHANGED
@@ -7,6 +7,10 @@ class EndpointHandler:
7
  # Configuração do modelo
8
  self.model_name_or_path = "souzat19/Llama3.1_fn14133.29122024"
9
 
 
 
 
 
10
  print("Initializing tokenizer...")
11
  # Inicialização do tokenizer
12
  self.tokenizer = AutoTokenizer.from_pretrained(
@@ -18,10 +22,9 @@ class EndpointHandler:
18
  # Inicialização do modelo com configurações mínimas
19
  self.model = AutoModelForCausalLM.from_pretrained(
20
  self.model_name_or_path,
21
- device_map=None, # Desativa mapeamento automático
22
  torch_dtype=torch.float32,
23
  trust_remote_code=True
24
- ).cpu() # Força o uso de CPU
25
 
26
  print("Model initialized successfully")
27
 
@@ -51,6 +54,9 @@ Você é um assistente especializado em planejamento de compras públicas de aco
51
  truncation=True,
52
  max_length=4096
53
  )
 
 
 
54
 
55
  # Gera a resposta
56
  with torch.no_grad():
 
7
  # Configuração do modelo
8
  self.model_name_or_path = "souzat19/Llama3.1_fn14133.29122024"
9
 
10
+ # Detecta se GPU está disponível
11
+ self.device = "cuda" if torch.cuda.is_available() else "cpu"
12
+ print(f"Using device: {self.device}")
13
+
14
  print("Initializing tokenizer...")
15
  # Inicialização do tokenizer
16
  self.tokenizer = AutoTokenizer.from_pretrained(
 
22
  # Inicialização do modelo com configurações mínimas
23
  self.model = AutoModelForCausalLM.from_pretrained(
24
  self.model_name_or_path,
 
25
  torch_dtype=torch.float32,
26
  trust_remote_code=True
27
+ ).to(self.device) # Move para GPU se disponível
28
 
29
  print("Model initialized successfully")
30
 
 
54
  truncation=True,
55
  max_length=4096
56
  )
57
+
58
+ # Move input para mesmo device do modelo
59
+ inputs = {k: v.to(self.device) for k, v in inputs.items()}
60
 
61
  # Gera a resposta
62
  with torch.no_grad():