Repository navigation
Conversation
…/stream load_model(blob=...) and load_model(stream=...) did not repopulate _init_params (and did not reset _canonized_params), unlike the file-path load path. As a result _get_default_prediction_type() fell back to 'RawFormulaVal' and predict() returned log-scale raw values for losses with a link function (Poisson, Tweedie) instead of the exponentiated target. Extract the shared post-load param refresh into _refresh_params_from_model() and call it from all three load paths. Fixes catboost#3103.
andrey-khropov
left a comment
There was a problem hiding this comment.
-
Let's move
self._init_params = {}to_refresh_params_from_modelto avoid copy-paste. -
Please use
test_output_path(OUTPUT_MODEL_PATH)for the model file as it is done in other tests. There's no need to delete it yourself, it will be deleted automatically by the test framework.
…use test_output_path
Address review comments: consolidate the _init_params = {} reset inside
_refresh_params_from_model (called from all three load paths) and use the
standard test_output_path(OUTPUT_MODEL_PATH) helper in the regression test.
|
Thanks for the review! Both points addressed:
|
_load_from_blob now refreshes _init_params from the model (needed for the Poisson-link fix), but __setstate__ relies on _load_from_blob and then merges the pickled state on top. Reset _init_params after the blob load so the restored params match __getstate__ exactly instead of leaking model-derived defaults (fixes test_set_params_with_synonyms).
|
Pushed a follow-up: |
|
@andrey-khropov has imported your pull request. If you are a Yandex employee, you can view this diff. |
|
✅ This pull request is being closed because it has been successfully merged into our internal monorepository. |
…/stream ## Summary Fixes #3103 — `load_model(blob=...)` and `load_model(stream=...)` silently dropped the model's default prediction link function, so `predict()` returned `RawFormulaVal` (log-scale) instead of the exponentiated target for losses with a link function (Poisson, Tweedie). ## Root cause The file-path load path (`_load_model`) resets `_init_params` and repopulates it from the loaded model, then invalidates `_canonized_params`. The blob/stream paths (`_load_from_blob`, `_load_from_stream`) only called `_set_trained_model_attributes()` and left `_init_params` empty/stale. `_get_default_prediction_type()` reads `loss_function` from the canonized params, so it fell back to `'RawFormulaVal'`. ## Changes - Extract the shared post-load refresh into `_refresh_params_from_model()`. - Call it from all three load paths (`_load_model`, `_load_from_blob`, `_load_from_stream`), each resetting `_init_params = {}` before loading so stale params from a previous load don't leak. ## Test Added `test_load_model_preserves_poisson_link`: trains a small Poisson model, saves it, loads via file path / blob / stream, and asserts the predictions match (and are exponentiated, not raw). ## Verification ``` path : 1.318882 blob : 1.318882 # previously 0.276785 (raw) stream: 1.318882 # previously 0.276785 (raw) ``` --- Pull Request resolved: #3184 commit_hash:f98e62fa70d063a5b44bb0e8da88df7e5db07653
Summary
Fixes #3103 —
load_model(blob=...)andload_model(stream=...)silently dropped the model's default prediction link function, sopredict()returnedRawFormulaVal(log-scale) instead of the exponentiated target for losses with a link function (Poisson, Tweedie).Root cause
The file-path load path (
_load_model) resets_init_paramsand repopulates it from the loaded model, then invalidates_canonized_params. The blob/stream paths (_load_from_blob,_load_from_stream) only called_set_trained_model_attributes()and left_init_paramsempty/stale._get_default_prediction_type()readsloss_functionfrom the canonized params, so it fell back to'RawFormulaVal'.Changes
_refresh_params_from_model()._load_model,_load_from_blob,_load_from_stream), each resetting_init_params = {}before loading so stale params from a previous load don't leak.Test
Added
test_load_model_preserves_poisson_link: trains a small Poisson model, saves it, loads via file path / blob / stream, and asserts the predictions match (and are exponentiated, not raw).Verification