You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add multi-method support for ETRecord edge dialect programs (pytorch#17185)
## Summary
This PR implements proper multi-method support for ETRecord while fixing
fundamental ETRecord lifecycle issues that were exposed during testing.
## Multi-Method ETRecord Support
- **VLM Model Support**: Added support for models with multiple methods
(vision_encoder, text_decoder, etc.) required for Vision-Language Models
- **Flexible Storage**: ETRecord now stores `edge_dialect_program` as
`Dict[str, ExportedProgram]` for multi-method cases
- **Backward Compatibility**: Single-method cases still store as
`ExportedProgram` for seamless compatibility
- **Consistent Format**: Always uses new multi-method serialization
format for future-proofing
## ETRecord Lifecycle Separation
- **Fixed Shared State Issue**: EdgeProgramManager and
ExecutorchProgramManager were incorrectly sharing ETRecord instances
- **Proper Separation**: `EdgeProgramManager.to_executorch()` now
creates separate ETRecord for ExecutorchProgramManager
- **Edge Stage Integrity**: EdgeProgramManager retains pure edge-stage
ETRecord (`_debug_handle_map = None`)
- **Complete Records**: ExecutorchProgramManager gets complete ETRecord
with executorch data populated
- **Immutable Design**: Follows immutable snapshot principle where each
transformation stage owns appropriate data
## Test Corrections
- **Pure Edge Testing**: Fixed `test_to_edge_with_etrecord_generation`
to test edge-stage behavior without executorch interference
- **Correct Comparisons**: Fixed graph comparison logic that incorrectly
mixed edge/executorch transformation states
- **Full Coverage**: All 48 ETRecord tests pass with proper lifecycle
separation
## Architecture Impact
The changes establish clear architectural boundaries between
transformation stages:
- **Edge Stage**: ETRecord captures exported program + edge dialect
program
- **Executorch Stage**: ETRecord captures everything from edge +
executorch-specific data
- **No Shared State**: Each manager maintains its own appropriate
ETRecord snapshot
This enables ETRecord to support complex multi-method models used in VLM
workflows while maintaining clean separation of concerns and preventing
state corruption between transformation stages.
## Testing
- ✅ All 48 ETRecord tests pass
- ✅ Multi-method serialization/deserialization works correctly
- ✅ Backward compatibility maintained for single-method cases
- ✅ Lifecycle separation prevents state corruption
- ✅ VLM workflows can now use ETRecord for debugging and inspection
Differential Revision:
[D92215098](https://www.internalfb.com/diff/D92215098)
Co-authored-by: Claude Sonnet 4 <[email protected]>
0 commit comments