Skip to content

fix(trainer): unpack train_func_parameters as kwargs in localprocess backend - #769

Open
SahilKumar75 wants to merge 1 commit into
kubeflow:mainfrom
SahilKumar75:fix/localprocess-train-func-kwargs
Open

fix(trainer): unpack train_func_parameters as kwargs in localprocess backend#769
SahilKumar75 wants to merge 1 commit into
kubeflow:mainfrom
SahilKumar75:fix/localprocess-train-func-kwargs

Conversation

@SahilKumar75

Copy link
Copy Markdown
Contributor

What happened?

The LocalProcess backend generates the training function call by embedding train_func_parameters directly into the generated script as a single positional argument:

func_code = f"{func_code}\n{train_func.__name__}({train_func_parameters})\n"

Since train_func_parameters is a dict, this produces a call like train_func({'lr': 0.01, 'num_epochs': 5}) instead of train_func(lr=0.01, num_epochs=5). Any training function that takes named parameters raises a TypeError as soon as it is run through LocalProcessBackend.

The Kubernetes backend already handles this correctly with double star unpacking:

func_call = f"{train_func.__name__}(**{train_func_parameters})"

What did you expect to happen?

CustomTrainer func_args should be passed as keyword arguments on the LocalProcess backend too, consistent with the Kubernetes backend.

Fix

Apply the same ** unpacking used by the Kubernetes backend to the LocalProcess backend's generated call. Added kubeflow/trainer/backends/localprocess/utils_test.py (did not previously exist) covering both the parameterized and no argument cases, asserting the generated script is valid, executable Python.

make test-python and make verify pass locally.

…backend

The LocalProcess backend embedded train_func_parameters as a single
positional dict argument instead of unpacking it as keyword arguments,
unlike the Kubernetes backend which already does this correctly. Any
CustomTrainer using func_args with LocalProcessBackend would fail with
a TypeError since the training function receives one dict positional
argument instead of its named parameters.

Signed-off-by: Sahil Kumar Singh <60318530+SahilKumar75@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 22, 2026 12:41

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@google-oss-prow

Copy link
Copy Markdown
Contributor

[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 electronic-waste 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

@SahilKumar75

Copy link
Copy Markdown
Contributor Author

The required checks are passing. Could a Kubeflow approver please review this change and add LGTM if it is ready?

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.

2 participants