Spaces:
Runtime error
Runtime error
injected code for phi-3 model error
Browse files
app.py
CHANGED
@@ -46,4 +46,18 @@ demo = gr.Interface(
|
|
46 |
description="Enter a text and a JSON template to extract structured information and generate a response using NuExtract.",
|
47 |
)
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
demo.launch(share=True)
|
|
|
46 |
description="Enter a text and a JSON template to extract structured information and generate a response using NuExtract.",
|
47 |
)
|
48 |
|
49 |
+
|
50 |
+
# Patch Phi-3.5-mini-instruct's `prepare_inputs_for_generation`
|
51 |
+
def patched_prepare_inputs_for_generation(self, input_ids, past_key_values=None, **kwargs):
|
52 |
+
if past_key_values is not None:
|
53 |
+
max_cache_length = past_key_values.get_seq_length() # Fix here
|
54 |
+
else:
|
55 |
+
max_cache_length = None
|
56 |
+
return self._default_prepare_inputs_for_generation(input_ids, past_key_values, **kwargs)
|
57 |
+
|
58 |
+
# Apply the patch dynamically
|
59 |
+
if hasattr(model, "prepare_inputs_for_generation"):
|
60 |
+
model._default_prepare_inputs_for_generation = model.prepare_inputs_for_generation
|
61 |
+
model.prepare_inputs_for_generation = patched_prepare_inputs_for_generation.__get__(model)
|
62 |
+
|
63 |
demo.launch(share=True)
|