fix: handle inconsistent return values from build_model #519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#Description:
The current build_model() function has inconsistent return behavior depending on configuration flags:
When args.encoder_only=True or args.backbone_only=True: returns a tuple (component, None, None)
When building full model: returns a single model object
This causes issues in the main function where the code expects three return values but sometimes receives only one. The error occurs when trying to unpack: model, criterion, postprocessors = build_model(args).
#Changes Made:
1.Modified the model building section in main() to handle both return patterns
2.Replaced the direct unpacking with flexible handling that works for both single values and tuples
3.Added logic to extract the model from tuple when needed, or use the single value directly
#Code Changes:
python
Before (fails when build_model returns single value):
model, criterion, postprocessors = build_model(args)
After (handles both patterns):
result = build_model(args)
model = result[0] if isinstance(result, tuple) else result
#Benefits:
✅ Fixes ValueError: not enough values to unpack when building full model
✅ Maintains backward compatibility with existing configurations
✅ Supports both encoder_only/backbone_only modes and full model building
✅ No changes needed to the build_model() function itself
✅ Clear and concise error handling
#Impact:
The code now works correctly for all configuration modes without runtime errors
Future changes to build_model() return patterns will be handled gracefully
Model export functionality (ONNX/TensorRT) continues to work as expected