Uh oh!
There was an error while loading. Please reload this page.
') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })();
There was an error while loading. Please reload this page.
source_code (no repack) for image_uri / ModelTrainer builds #6105
PySDK Version
Describe the bug
ModelBuilderaccepts asource_codeargument, documented as "Source code configuration forcustom inference code." When building a model from an existing script-mode container
(
image_uri) together with a trained model artifact (a model data S3 URI), I expectModelBuilder.build()to repack the providedsource_codeinto the model artifact — i.e. bakecode/intomodel.tar.gz— exactly the way the classicsagemaker.model.Model(model_data=…, entry_point=…, source_dir=…)did, and the way pipelines didvia
_RepackModelStep.A self-contained artifact is required for
register(): a registered model package is persisted andserved on its own, so it cannot depend on an external
SAGEMAKER_SUBMIT_DIRECTORYpointing at atransient S3 source tarball.
Instead, for any
image_uri-based build with nomodel/inference_spec,ModelBuilderclassifies the build as passthrough and silently discards
source_code:_build_for_passthrough()resetsself.source_dir = Noneandself.entry_point = None, sois_repack()returnsFalseand no code is ever packaged. The resulting artifact contains the modeldata but none of the inference code, and
register()produces a model package that fails toserve (no
model_fn/input_fn/predict_fn/output_fn).This is existing behavior in v2 of this SDK so this is a regression.
To reproduce
Case 1 —
image_uri+ model URI +source_code(silent drop):Case 2 —
ModelTrainer(the natural train→serve flow) +source_code:Expected behavior
When a model artifact (a model URI - via
model_path, aModelTrainer, or aTrainingJob) issupplied alongside
source_code,ModelBuilder.build()should repack the source code into themodel artifact and produce a self-contained
model.tar.gz(code undercode/), mirroring theclassic
Model+_RepackModelStepbehavior.source_codemust not be silently ignored.Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.
System information
A description of your system. Please provide:
sagemaker==3.15.1,sagemaker-core==2.16.0Additional context
Root cause / code references
All references are to
sagemaker/serve/model_builder.pyinsagemaker==3.15.1.source_codeis honored initially._initialize_script_mode_variables()maps it onto thescript-mode attributes:
L1362-1376:self.entry_point = self.source_code.entry_script;self.source_dir = self.source_code.source_dir._build_validations()forces passthrough for image-only builds (both first- andnon-first-party images):
L1564-1572:image_uri+is_1p_image_uri(...)+ nomodel+ noinference_spec→
self._passthrough = True.L1574-1582:image_uri+ notis_1p_image_uri(...)+ nomodel+ noinference_spec→
self._passthrough = True._build_for_passthrough()then discards the source code:L1603-1605:is_repack()therefore returnsFalse, so_upload_code(..., repack=True)→repack_model(...)never runs:L1924-1925:if self.source_dir is None or self.entry_point is None: return False.The repack code path exists (
_upload_code(..., repack=True)atL1932, callingrepack_model(...)),but it is unreachable for these inputs.
ModelTrainer-specific manifestationmodel=<ModelTrainer>requiresinference_spec—_build_validations()raises"InferenceSpec is required when using ModelTrainer, ..." at
L1527-1536. Sosource_codecannot be combined with a
ModelTrainer.inference_specis supplied with aModelTrainer, repack is explicitly disabled —is_repack()short-circuits atL1927-1928:serve.pkl(cloudpickle) path, which doesnot repack a multi-file
source_dirinto the artifact.Net: there is no combination of
ModelBuilderinputs that produces"model data URI + inference source code → repacked, self-contained
model.tar.gz" for a script-modeframework or custom image. This blocks migrating classic
Model/PipelineModelregistration(which relied on the repack) to
ModelBuilder.Suggested fix
For
image_uri-based builds, honorsource_codeinstead of nulling it in_build_for_passthrough(): when both a model artifact andsource_codeare present, take therepack path (
_upload_code(..., repack=True)) so the code is baked into the artifact. Equivalently,allow
source_code+ a model artifact (script-mode) with aModelTrainerwithout requiring anInferenceSpec, so the classic train → repack → register flow remains expressible in v3.