Skip to content

FrameworkProcessor._package_code ignores _pipeline_config.code_hash, so ProcessingStep caching never hits when source_dir is used #6493

Closed

Description

@feiyangliu-Tink

Describe the bug

When a ProcessingStep is built from a FrameworkProcessor using source_dir=/dependencies=, CacheConfig never produces a cache hit, even with byte-identical code and inputs.

The SDK computes the correct content hash for this case and plumbs it into the step-compilation context, but the multi-file upload path never reads it:

  • get_processing_code_hash() (sagemaker-core/src/sagemaker/core/workflow/utilities.py) has an explicit # FrameworkProcessor branch returning hash_files_or_dirs([code, source_dir] + dependencies).
  • _steps_compiler.py sets it as code_hash on _pipeline_config before replaying the step's deferred processor.run().
  • ScriptProcessor._upload_code() consults it and builds a content-addressed key:
    if _pipeline_config and _pipeline_config.code_hash:
        desired_s3_uri = s3.s3_path_join(..., _pipeline_config.pipeline_name,
                                         self._CODE_CONTAINER_INPUT_NAME,
                                         _pipeline_config.code_hash)
  • FrameworkProcessor._package_code() never references _pipeline_config. It builds the path from the job name instead:
    s3_uri = s3.s3_path_join(self._s3_code_prefix(), job_name, "source", "sourcedir.tar.gz")
    and job_name comes from _generate_current_job_name() → name_from_base(...), i.e. timestamped on every compile.

Since ProcessingInputs is a documented cache-key attribute, the differing sourcedir.tar.gz URI changes the step signature on every upsert()/definition() call, so no step can ever match a previous run.

This looks like the ScriptProcessor half of #2736's fix never being carried over to the FrameworkProcessor path.

To reproduce

proc = FrameworkProcessor(image_uri=IMAGE, role=ROLE, instance_count=1,
                          instance_type="ml.m5.large", base_job_name="probe",
                          sagemaker_session=PipelineSession())
step = ProcessingStep(name="Probe",
                      cache_config=CacheConfig(enable_caching=True, expire_after="30d"),
                      step_args=proc.run(code="entry.py", source_dir="steps/probe"))
pipeline = Pipeline(name="probe", steps=[step], sagemaker_session=session)

# compile twice, with no code changes in between
for _ in range(2):
    d = json.loads(pipeline.definition())
    print([i["S3Input"]["S3Uri"] for i in d["Steps"][0]["Arguments"]["ProcessingInputs"]
           if i["InputName"] == "code"])

Output (SDK 3.24.0):

['s3://.../probe-2026-10-16-11-12-35-333/source/']
['s3://.../probe-2026-10-16-11-12-37-141/source/']

The entrypoint input (runproc.sh) is content-addressed correctly in the same definition, which makes the asymmetry easy to see.

Expected behaviour

The sourcedir.tar.gz key should be content-addressed from _pipeline_config.code_hash when compiling inside a pipeline, the way ScriptProcessor._upload_code already does — so that an unchanged source_dir yields an unchanged ProcessingInputs and caching can match.

Notes

  • PipelineDefinitionConfig(use_custom_job_prefix=True) does not work around this. It trims the timestamp from ProcessingJobName in the compiled definition, but the S3 upload path is built during run(), before trim_request_dict rewrites the definition, so the path keeps its timestamp. Verified by compiling twice under both settings.
  • A working workaround is to pass an explicit, content-derived job_name to processor.run(), which makes the upload path deterministic. ProcessingJobName is popped from the definition by default, so this does not affect job naming at execution time:
    code_hash = get_processing_code_hash(entry_abs_path, source_dir, dependencies)
    processor.run(..., job_name=f"{step}-{code_hash[:12]}")
  • This is easy to miss because it fails open: the step simply always reruns, which is hard to distinguish from "the inputs genuinely changed". Nothing errors or warns. It only bites when source_dir is used (needed to share Python modules across steps) and caching is enabled and someone verifies hits actually occur.
  • Related: upserting a pipeline kills caching #2736 (the partial fix), Use of source_dir argument for FrameworkProcessor disables step caching functionality #4246 (source_dir contents being hashed), TuningStep changing sagemaker_job_name in StaticHyperParameters when run get pipeline definition and pipeline upsert and kill cache #3651 (the same class of problem for TuningStep, closed without a fix).

System information

  • SDK version: sagemaker==3.24.0 (sagemaker-core 2.25.0, sagemaker-mlops 1.25.0); code paths above also verified present on master @ ce3ac25
  • Framework: FrameworkProcessor against an AWS PyTorch DLC
  • Python: 3.12 (container), 3.14 (client)
  • Region: eu-north-1

Activity

  1. Nimisha987 commented on Oct 16, 2026

    @Nimisha987

    Hi! I'd love to contribute to this issue.

    I've been exploring the reported caching issue and would like to investigate why FrameworkProcessor._package_code() does not use _pipeline_config.code_hash, unlike ScriptProcessor._upload_code(). As described, this can cause the generated S3 URI to change across repeated pipeline compilations even when the source code and dependencies remain unchanged, preventing the expected pipeline cache hits.

    I'd like to work on reproducing this behavior, adding a regression test to cover repeated compilations with unchanged source code, and implementing a minimal fix that keeps the generated S3 URI deterministic when a pipeline code hash is available, while preserving the existing behavior outside pipeline compilation.

    Before proceeding with the implementation, could a maintainer please confirm whether this issue is available to work on and whether I could be assigned to it?

    Thank you for the detailed bug report!

  2. Nimisha987 commented on Oct 16, 2026

    @Nimisha987

    Hi! I noticed that you've opened a PR for this issue. I'm also interested in contributing and have started investigating the reported caching behavior.

    I'd love to help strengthen the fix, particularly by reviewing the regression tests and checking edge cases such as unchanged source files, modified dependencies, and behavior outside pipeline compilation.

    Would you be open to additional testing or review contributions on this PR? I'd be happy to help where needed.

  3. added a commit that references this issue on Oct 22, 2026
    b5a4d37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions