Reyad-Ahmmed commited on
Commit
8492ae4
·
verified ·
1 Parent(s): 9d6ef4e

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +11 -0
handler.py CHANGED
@@ -48,11 +48,22 @@ class EndpointHandler:
48
  # Tokenize input text
49
  input_ids = self.tokenizer(user_text, return_tensors="pt").input_ids
50
 
 
 
 
51
  # Perform inference
52
  with torch.no_grad():
53
  output_ids = self.model.generate(input_ids, max_length=100, temperature=0.3)
54
 
55
  json_output = self.tokenizer.decode(output_ids[0], skip_special_tokens=True)
 
 
 
 
 
 
 
 
56
  # return json.loads(json_output)
57
  try:
58
  return json.loads(json_output)
 
48
  # Tokenize input text
49
  input_ids = self.tokenizer(user_text, return_tensors="pt").input_ids
50
 
51
+ # Measure inference time
52
+ start_time = time.time()
53
+
54
  # Perform inference
55
  with torch.no_grad():
56
  output_ids = self.model.generate(input_ids, max_length=100, temperature=0.3)
57
 
58
  json_output = self.tokenizer.decode(output_ids[0], skip_special_tokens=True)
59
+
60
+ end_time = time.time()
61
+ inference_time = end_time - start_time # Calculate time taken
62
+
63
+ # Print inference time
64
+ print(f"Inference Time: {inference_time:.4f} seconds")
65
+
66
+
67
  # return json.loads(json_output)
68
  try:
69
  return json.loads(json_output)