Skip to content

fix(model_zoo): keep session options when unpickling a session - #2907

Open
huangkongsheng wants to merge 1 commit into
deepinsight:masterfrom
huangkongsheng:fix/pickle-session-options
Open

huangkongsheng wants to merge 1 commit into
deepinsight:masterfrom
huangkongsheng:fix/pickle-session-options

Conversation

@huangkongsheng

Copy link
Copy Markdown

Fixes #2899 (the pickle part).

@sigma-plus offered to send a PR for this in the issue, so picking it up here - hope that's ok.

PickableInferenceSession dropped the caller's sess_options on a pickle round-trip: __getstate__ didn't record them, so __setstate__ rebuilt the session with defaults. A restored session came back with the default thread pool sizing, which oversubscribes the CPU in quota-limited containers (the ~185x slowdown in the issue).

The fix stores the scalar session options in __getstate__ (reusing the attribute list copy_session_options already has) and applies them in __setstate__ before re-creating the session. Old pickles without the new key still unpickle fine.

Tests: new tests/model_zoo/test_pickable_session_options.py - asserts intra_op_num_threads/inter_op_num_threads survive the round-trip, that default-option sessions still pickle, and that states without the new key are still accepted. They build a tiny Identity ONNX model on the fly, so no downloads or sample data are needed. All 3 pass locally; the rest of the model_zoo suite is unchanged (the 19 failures there on Windows are pre-existing symlink/license ones, also present without this change).

PickableInferenceSession dropped the caller's sess_options during a
pickle round-trip: __getstate__ did not record them, so __setstate__
rebuilt the session with defaults. A restored session therefore came
back with the default thread pool sizing, which oversubscribes the CPU
in quota-limited containers (the 185x slowdown reported in deepinsight#2899).

__getstate__ now stores the scalar session options (the same attribute
list copy_session_options uses) and __setstate__ applies them before
re-creating the session. Old pickles without the new key still work.

Covered by tests/model_zoo/test_pickable_session_options.py, which uses
a tiny programmatically generated Identity ONNX model - no downloads,
no sample data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

model_zoo.get_model silently drops sess_options → thread oversubscription in CPU-quota containers (50s vs 0.27s inference)

1 participant