Skip to content

fix(trainer): inject HF_HOME on fine_tune pods to fix OpenShift PermissionError#83

Open
ptalgulk01 wants to merge 1 commit into
kubeflow:mainfrom
ptalgulk01:fix-hf-home-openshift
Open

fix(trainer): inject HF_HOME on fine_tune pods to fix OpenShift PermissionError#83
ptalgulk01 wants to merge 1 commit into
kubeflow:mainfrom
ptalgulk01:fix-hf-home-openshift

Conversation

@ptalgulk01

@ptalgulk01 ptalgulk01 commented Jul 15, 2026

Copy link
Copy Markdown

Description

  • Fixes fine_tune() failure on OpenShift where pods crash with PermissionError: [Errno 13] Permission denied: '/.cache' becausevHuggingFace defaults to writing to the read-only /.cache/huggingface under restricted SCC.
  • Injects HF_HOME=/workspace/.hf on all fine_tune pods (node, dataset-initializer, model-initializer) via _build_runtime_patch().
  • /workspace is always writable (provided by the ClusterTrainingRuntime PVC).

Changes

  • Added HF_HOME_PATH constant and pass it as env to _build_runtime_patch() in fine_tune()
  • Updated _build_runtime_patch() to propagate env to initializer containers (previously only volume_mounts were forwarded)
  • Updated system prompt and platform-fixes resource to document the auto-injection behavior

Related Issue

Fixes #33

Checklist

  • I have read the CONTRIBUTING guide
  • Tests pass locally (make test-python)
  • Linting passes (make verify)
  • Documentation updated (if applicable)
  • My commits are signed off (git commit -s)

Testing

  • Unit tests
  • Integration tests
  • E2E tests
  • Manually tested (describe below)

…hift compatibility

Signed-off-by: Prachiti Talgulkar <ptalgulk01@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 15, 2026 05:34
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign astefanutti for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown

🎉 Welcome to the Kubeflow MCP Server! 🎉

Thanks for opening your first PR! We're happy to have you as part of our community 🚀

Here's what happens next:

  • If you haven't already, please check out our Contributing Guide for repo-specific guidelines and the Kubeflow Contributor Guide for general community standards
  • Our team will review your PR soon! cc @kubeflow/kubeflow-sdk-team

Join the community:

Feel free to ask questions in the comments if you need any help or clarification!
Thanks again for contributing to Kubeflow! 🙏

@ptalgulk01 ptalgulk01 changed the title fix(trainer): inject HF_HOME on fine_tune pods to fix OpenShift PermissionError fix(trainer): inject HF_HOME on fine_tune pods to fix OpenShift PermissionError Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds HF_HOME injection intended to make fine-tuning compatible with OpenShift’s restricted filesystem.

Changes:

  • Injects HF_HOME=/workspace/.hf through runtime patches.
  • Propagates environment variables to initializer containers.
  • Documents the automatic cache configuration.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
kubeflow_mcp/trainer/api/training.py Adds and propagates HF_HOME.
kubeflow_mcp/trainer/__init__.py Updates trainer instructions.
kubeflow_mcp/trainer/resources/platform-fixes.md Documents OpenShift cache handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

affinity=affinity,
service_account_name=service_account_name,
image_pull_secrets=image_pull_secrets,
env=hf_home_env,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptalgulk01 this seems legit issue.. can we fix this?
This goes through RuntimePatch / spec.runtimePatches. Please put node env on spec.trainer.env and initializer env on the initializer env fields.

Comment on lines +413 to +416
if has_initializers and (volumes or volume_mounts or env):
for init_name in ("dataset-initializer", "model-initializer"):
init_containers = None
if volume_mounts:
init_containers = [ContainerPatch(name=init_name, volume_mounts=volume_mounts)]
if volume_mounts or env:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptalgulk01 can you try resolving this copilot review, this seems legit too?


`fine_tune()` automatically sets `HF_HOME=/workspace/.hf` on all pods (node, dataset-initializer, model-initializer). This redirects HuggingFace cache writes from the default `/.cache/huggingface` (read-only under OpenShift's restricted SCC) to the writable `/workspace` PVC.

No user action is needed for `fine_tune()`. For `run_custom_training()` or `run_container_training()` that use HuggingFace libraries, pass:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. /workspace must be mounted writable.. that path isn’t auto-injected for container training. Otherwise HF_HOME=/workspace/.hf can still fail on a read-only rootfs.
cc: @ptalgulk01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fine_tune fails on OpenShift: no HF_HOME set, pods write to read-only /.cache

3 participants