Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
gary-boon
Claude
commited on
Commit
·
9e42df9
1
Parent(s):
070f9b8
Fix: Handle single-element tuple outputs in layer hook
Browse files- Fixed "tuple index out of range" when output has only one element
- Properly checks tuple length before accessing output[1:]
- Handles all output format cases correctly
The previous fix assumed output tuples always had multiple elements,
but some layers return single-element tuples.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- backend/model_service.py +16 -10
backend/model_service.py
CHANGED
|
@@ -303,18 +303,24 @@ class ModelManager:
|
|
| 303 |
# The output is (hidden_states, optional_attention_weights, ...)
|
| 304 |
# We want to pass the input hidden states as if the layer did nothing
|
| 305 |
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
else:
|
| 313 |
-
#
|
| 314 |
-
return
|
| 315 |
else:
|
| 316 |
-
#
|
| 317 |
-
return
|
| 318 |
return hook
|
| 319 |
|
| 320 |
# Apply hooks and log what's being disabled
|
|
|
|
| 303 |
# The output is (hidden_states, optional_attention_weights, ...)
|
| 304 |
# We want to pass the input hidden states as if the layer did nothing
|
| 305 |
|
| 306 |
+
# Get the input hidden states
|
| 307 |
+
if isinstance(input, tuple) and len(input) > 0:
|
| 308 |
+
input_hidden_states = input[0]
|
| 309 |
+
else:
|
| 310 |
+
input_hidden_states = input
|
| 311 |
+
|
| 312 |
+
# Return in the same format as the output
|
| 313 |
+
if isinstance(output, tuple):
|
| 314 |
+
# Check if there are additional elements to preserve
|
| 315 |
+
if len(output) > 1:
|
| 316 |
+
# Keep any additional outputs (like attention weights)
|
| 317 |
+
return (input_hidden_states,) + output[1:]
|
| 318 |
else:
|
| 319 |
+
# Output is a single-element tuple, return the same
|
| 320 |
+
return (input_hidden_states,)
|
| 321 |
else:
|
| 322 |
+
# Output is a plain tensor, return input as plain tensor
|
| 323 |
+
return input_hidden_states
|
| 324 |
return hook
|
| 325 |
|
| 326 |
# Apply hooks and log what's being disabled
|