Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] Add env & env_from in client tune #2235

Merged
merged 2 commits into from
Nov 17, 2023

Conversation

shipengcheng1230
Copy link
Contributor

@shipengcheng1230 shipengcheng1230 commented Oct 24, 2023

What this PR does / why we need it:

The env and env_from cannot be directly set in the client tune method. Recently I found myself need to set up proxy environment variables for cross-region data access. Doing so inside the existing python objective function seems less desirable than having them set through these two specifications.

This PR enables this capability. By default, these two are set to None which aligns with V1Container. Therefore, behavior is not modified when not setting them.

Also, there was a missing of cmaes package when testing optuna suggestion. Therefore I added it in the optuna requirements.txt. (Rebased the master change)

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

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

This idea looks good.

/assign @andreyvelich

@@ -2,3 +2,4 @@ grpcio>=1.41.1
protobuf>=3.19.5, <=3.20.3
googleapis-common-protos==1.53.0
optuna>=3.0.0
cmaes>=0.10.0
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we need this since optuna already specify the cmaes version:

https://github.com/optuna/optuna/blob/da9ec3d1622af4b08dae1964b6c54dfead1d5f9e/pyproject.toml#L69

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the cmaes is listed as an optional depedency. And in the GitHub CI it says

ModuleNotFoundError: No module named 'cmaes'

I think a change like from optuna>=3.0.0 to optuna[cmaes]>=3.0.0 is probably needed for the test to pass.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. Thanks for the clarifying. Let's specify cmaes>=0.10.0.

Copy link
Member

Choose a reason for hiding this comment

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

@shipengcheng1230 @tenzen-y Did optuna recently change their dependancies to make cmaes optional ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This commit moves it: optuna/optuna@78159b5

Comment on lines 178 to 179
env: Environment variable(s) to be attached to each trial container.
env_from: Source(s) of environment variables to be populated in each trial container.
Copy link
Member

Choose a reason for hiding this comment

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

Can we mention the types like resources_per_trial?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! I have added additional type descriptions of these two (4661b80)

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

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

Otherwise lgtm.

Comment on lines 144 to 145
env: Union[Dict[str, str], List[V1EnvVar], None] = None,
env_from: Union[V1EnvFromSource, List[V1EnvFromSource], None] = None,
Copy link
Member

@andreyvelich andreyvelich Oct 31, 2023

Choose a reason for hiding this comment

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

Should we keep the name associated with Trials ? E.g. user could misunderstand this as environment for Algorithm Service.
E.g. name it as trials_env or env_per_trial similar to resources_per_trial.
Also, I think we can allow to set Dict[str, str], List[V1EnvVar], or List[V1EnvFromSource] in this parameter.

WDYT @shipengcheng1230 @tenzen-y @johnugeorge ?

Copy link
Contributor Author

@shipengcheng1230 shipengcheng1230 Oct 31, 2023

Choose a reason for hiding this comment

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

I like env_per_trial which is more descriptive and consistent with resources_per_trial!

Also, I think we can allow to set Dict[str, str], List[V1EnvVar], or List[V1EnvFromSource] in this parameter.

In this case, we are merging the two env and env_from into a single env_per_trial (or trials_env), am I right? (I also love the simplicity here for users)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think so @shipengcheng1230, we can accept multiple types for env_per_trial parameter.
What do you think about this name @tenzen-y @johnugeorge ?

Copy link
Contributor Author

@shipengcheng1230 shipengcheng1230 Nov 1, 2023

Choose a reason for hiding this comment

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

Here is the tentative implementation 12eea64 in which, the env_per_trial can be a list mixturing of V1EnvVar or V1EnvFromSource. Let me know your thoughts!

Copy link
Member

Choose a reason for hiding this comment

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

env_per_trial looks great!

@tenzen-y
Copy link
Member

tenzen-y commented Nov 3, 2023

Can you rebase this PR since we fixed the optuna dependency issue?

@shipengcheng1230
Copy link
Contributor Author

Cool, done rebase and let me know what else is needed!

@@ -140,6 +141,7 @@ def tune(
parameters: Dict[str, Any],
base_image: str = constants.BASE_IMAGE_TENSORFLOW,
namespace: Optional[str] = None,
env_per_trial: Union[Dict[str, str], List[Union[V1EnvVar, V1EnvFromSource]], None] = None,
Copy link
Member

Choose a reason for hiding this comment

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

Should we make this type Optional and import libs from Kubernetes client, similar to other Kubernetes modules ?

Suggested change
env_per_trial: Union[Dict[str, str], List[Union[V1EnvVar, V1EnvFromSource]], None] = None,
env_per_trial: Optional[Union[Dict[str, str], List[Union[client.V1EnvVar, client.V1EnvFromSource]]]] = None,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the great suggestion, I wasn't aware that those client.models are also importable from the client level!

@andreyvelich
Copy link
Member

Sorry for the late reply @shipengcheng1230, I left one small comment.

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

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

/approve

I'll leave lgtm on @andreyvelich.

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shipengcheng1230, tenzen-y

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

The pull request process is described here

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

@andreyvelich
Copy link
Member

Thank you for the update @shipengcheng1230!
/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Nov 17, 2023
@google-oss-prow google-oss-prow bot merged commit f4c8861 into kubeflow:master Nov 17, 2023
59 checks passed
@andreyvelich andreyvelich mentioned this pull request Jan 24, 2024
11 tasks
@andreyvelich andreyvelich added this to the Katib v0.17.0 Release milestone Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants