fix(serve): repack source_code for image_uri/ModelTrainer builds - #6112
fix(serve): repack source_code for image_uri/ModelTrainer builds#6112lucasjia-aws wants to merge 4 commits into
Conversation
ModelBuilder classified any image_uri build with a model artifact and source_code (no model/inference_spec) as passthrough and dropped the inference code, so build() produced a model.tar.gz without code/ and register() yielded a package that could not serve. This regressed the classic v2 Model(model_data, entry_point, source_dir) repack behavior. In _build_for_passthrough(), distinguish a pure image-only deployment from an "image + model artifact + source_code" build. For the latter, keep the source code and bridge model_path to s3_model_data_url so the existing _upload_code(repack=True) path repacks the code into the model artifact, producing a self-contained tarball. Pure-image (Nova/BYOC) passthrough behavior is unchanged. ModelTrainer builds are covered too since they are normalized to model_path before validation. Also pass script_dependencies (a list derived from SourceCode) to repack_model instead of the deprecated self.dependencies auto-detect dict, which repack_model would otherwise iterate as filesystem paths.
|
related to issue #6105 |
|
Claude finished @lucasjia-aws's task in 6m 29s —— View job Code Review — PR #6112: repack
|
ModelBuilder classified any image_uri build without an in-memory model or inference_spec as passthrough, ignoring source_code. _build_for_ passthrough() then cleared source_dir/entry_point, so custom inference code was silently dropped: no repack occurred, the container pointed at the raw model artifact, register()/deploy() produced a model with no serving code. Regressed from v2 Model(model_data, entry_point, source_dir) + _RepackModelStep; introduced by aws#5969 (commit ebeb54c) which added the passthrough nulling. Fix the passthrough classification at its source: do not treat a build as passthrough when source_code is set (both 1P and non-1P image branches). Such builds route to the normal model-server path and repack the code into the artifact. Also: - Relax the _build_for_model_server guard to accept s3_model_data_url (a prebuilt training artifact) alongside model/MLflow/inference_spec. - In _upload_code repack, pass script_dependencies (a list) instead of the deprecated self.dependencies auto-detect dict, which repack_model would otherwise iterate as filesystem paths. - Update _build_for_model_server unit tests to set s3_model_data_url so the missing-parameter cases still validate.
|
Claude finished @lucasjia-aws's task in 8m 52s —— View job Code Review — PR #6112
The current diff takes a different approach than the PR description. The body describes bridging 1. Validation + repack key on
|
Restore v2-parity repack behavior for image_uri + model artifact + source_code builds by repacking inside _build_for_passthrough(), instead of gating these builds out of passthrough into the model-server path. Routing such builds to _build_for_model_server exposed pre-existing gaps in the server builders (e.g. _build_for_djl reads hf_model_config, which is unset when model is None) and diverged from the path that worked before serve 1.15.0. Repacking within passthrough matches the 1.12.0 behavior and keeps the fix self-contained. - _build_validations: drop the source_code passthrough exclusion so these builds stay on the passthrough path - _build_for_passthrough: when source_code and a model artifact are both present, bridge model_path to s3_model_data_url and repack into the artifact; otherwise keep the pure image-only passthrough behavior - _build_for_model_server: revert the s3_model_data_url guard relaxation - tests: revert the now-unneeded servers guard test changes Verified end-to-end (build -> deploy -> invoke) for both the ticket scenario (image_uri + model_server=DJL_SERVING + source_code + s3_model_data_url) and the aws#6105 scenario (no model_server).
Code Review — PR #6112
|

ModelBuilder classified any image_uri build with a model artifact and source_code (no model/inference_spec) as passthrough and dropped the inference code, so build() produced a model.tar.gz without code/ and register() yielded a package that could not serve. This regressed the classic v2 Model(model_data, entry_point, source_dir) repack behavior.
In _build_for_passthrough(), distinguish a pure image-only deployment from an "image + model artifact + source_code" build. For the latter, keep the source code and bridge model_path to s3_model_data_url so the existing _upload_code(repack=True) path repacks the code into the model artifact, producing a self-contained tarball. Pure-image (Nova/BYOC) passthrough behavior is unchanged. ModelTrainer builds are covered too since they are normalized to model_path before validation.
Also pass script_dependencies (a list derived from SourceCode) to repack_model instead of the deprecated self.dependencies auto-detect dict, which repack_model would otherwise iterate as filesystem paths.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.