Skip to content

fix(serve): set DJL HF cache defaults before _prepare_for_mode - #6435

Open
AkshayShah03 wants to merge 1 commit into
aws:masterfrom
AkshayShah03:fix/djl-hf-cache-before-prepare
Open

AkshayShah03 wants to merge 1 commit into
aws:masterfrom
AkshayShah03:fix/djl-hf-cache-before-prepare

Conversation

@AkshayShah03

Copy link
Copy Markdown

Issue #, if available: Relates to #5698

Description of changes:

#5733 made the DJL builder default HF_HOME and HUGGINGFACE_HUB_CACHE to /tmp, because /opt/ml/model is read-only on the endpoint when artifacts are mounted there. The setdefault calls run after _prepare_for_mode, though. For SAGEMAKER_ENDPOINT, _prepare_for_mode merges the DJL server's default env into env_vars with setdefault:

_DEFAULT_ENV_VARS = {..., "HF_HOME": "/opt/ml/model/", "HUGGINGFACE_HUB_CACHE": "/opt/ml/model/", ...}

So the /tmp defaults never took effect, and the endpoint still caches Hub downloads under the read-only /opt/ml/model, the #5698 symptom. #5733's tests mock _prepare_for_mode, which hid this.

This change applies the /tmp defaults before _prepare_for_mode. User-provided values still win because both places use setdefault. TRANSFORMERS_CACHE (also /opt/ml/model/ in the DJL defaults) is left as is, matching #5733's scope.

Testing:

  • New test_endpoint_build_hf_cache_is_tmp_with_real_prepare_for_mode runs the real _prepare_for_mode with only the S3 upload mocked. It fails before this change: HF_HOME is /opt/ml/model/.
  • Server builder tests: no new failures. The same 15 tests fail on master.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

aws#5733 made the DJL builder default HF_HOME and HUGGINGFACE_HUB_CACHE to
/tmp, because /opt/ml/model is read-only when artifacts are mounted there.
The setdefault calls ran after _prepare_for_mode, which for
SAGEMAKER_ENDPOINT merges the DJL server's default env (HF_HOME and
HUGGINGFACE_HUB_CACHE = /opt/ml/model/) into env_vars with setdefault, so
the /tmp defaults never took effect and the endpoint still cached HF
downloads under the read-only /opt/ml/model.

Apply the /tmp defaults before _prepare_for_mode. The existing tests mock
_prepare_for_mode; the new test runs it for real (S3 upload mocked).

Relates to aws#5698

This branch is waiting to be deployed

1 waiting deployment
manual-approval — bfe1519c Waiting Oct 12, 2026 by AkshayShah03 via wait-for-approval #1989
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.

1 participant