michailroussos commited on
Commit
5830d67
·
1 Parent(s): 78146c4
Files changed (1) hide show
  1. app.py +7 -20
app.py CHANGED
@@ -30,38 +30,24 @@ def respond(message, max_new_tokens, temperature, system_message=""):
30
  print("[DEBUG] Messages:", messages)
31
 
32
  # Tokenize inputs
33
- inputs = tokenizer.apply_chat_template(
34
  messages,
35
  tokenize=True,
36
  add_generation_prompt=True,
37
  return_tensors="pt",
38
  ).to("cuda")
39
 
40
- # Debug: Inspect input tensors
41
- print("[DEBUG] Tokenized inputs:", inputs)
42
 
43
- # Extract `input_ids` and `attention_mask`
44
- input_ids = inputs.get("input_ids", None)
45
- attention_mask = inputs.get("attention_mask", None)
46
-
47
- # Ensure tensors are present and properly shaped
48
- if input_ids is None or attention_mask is None:
49
- raise ValueError("Tokenized input is missing `input_ids` or `attention_mask`.")
50
- if input_ids.dim() != 2 or attention_mask.dim() != 2:
51
- raise ValueError(
52
- f"`input_ids` and `attention_mask` must be 2D tensors. "
53
- f"Found shapes: input_ids={input_ids.shape}, attention_mask={attention_mask.shape}"
54
- )
55
-
56
- # Debug: Shapes of tensors
57
- print(f"[DEBUG] input_ids shape: {input_ids.shape}")
58
- print(f"[DEBUG] attention_mask shape: {attention_mask.shape}")
59
 
60
  # Stream response
61
  text_streamer = TextStreamer(tokenizer, skip_prompt=True)
62
  response = model.generate(
63
  input_ids=input_ids,
64
- attention_mask=attention_mask,
65
  max_new_tokens=max_new_tokens,
66
  temperature=temperature,
67
  use_cache=True,
@@ -74,6 +60,7 @@ def respond(message, max_new_tokens, temperature, system_message=""):
74
  print("[ERROR]", str(e))
75
  return f"Error: {str(e)}"
76
 
 
77
  # Gradio UI
78
  demo = gr.Interface(
79
  fn=respond,
 
30
  print("[DEBUG] Messages:", messages)
31
 
32
  # Tokenize inputs
33
+ input_ids = tokenizer.apply_chat_template(
34
  messages,
35
  tokenize=True,
36
  add_generation_prompt=True,
37
  return_tensors="pt",
38
  ).to("cuda")
39
 
40
+ # Debug: Inspect input tensor
41
+ print("[DEBUG] input_ids:", input_ids)
42
 
43
+ # Ensure the input tensor has the correct dimensions
44
+ if input_ids.dim() != 2:
45
+ raise ValueError(f"`input_ids` must be a 2D tensor. Found shape: {input_ids.shape}")
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  # Stream response
48
  text_streamer = TextStreamer(tokenizer, skip_prompt=True)
49
  response = model.generate(
50
  input_ids=input_ids,
 
51
  max_new_tokens=max_new_tokens,
52
  temperature=temperature,
53
  use_cache=True,
 
60
  print("[ERROR]", str(e))
61
  return f"Error: {str(e)}"
62
 
63
+
64
  # Gradio UI
65
  demo = gr.Interface(
66
  fn=respond,