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

Add es trainer setup and loop #288

Merged
merged 1 commit into from
Sep 22, 2023
Merged

Conversation

salaast
Copy link
Collaborator

@salaast salaast commented Aug 8, 2023

No description provided.

sampler: corpus.Corpus,
tf_policy_path: str,
output_dir: str,
policy_saver_fn: Callable[..., Any],
Copy link

Choose a reason for hiding this comment

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

this seems... overly general?

config: configuration for blackbox optimization.
stubs: grpc stubs to inlining/regalloc servers
initial_step: the initial step for learning.
deadline: the deadline for requests to the inlining server.
Copy link

Choose a reason for hiding this comment

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

is this in seconds? either rename deadline_seconds or add it in the docstring.

perturbations = []
for _ in range(self._config.total_num_perturbations):
perturbations.append(
np.random.normal(size=(len(self._model_weights))) *
Copy link

Choose a reason for hiding this comment

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

in general if you wanted to write tests for this, you would pass a seed argument or a np.random.Generator object that was created with a seed; and use that to generate random numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not think I understand what you mean because it does not seem like _get_perturbations or np.random.normal accept a seed or generator argument

Copy link

Choose a reason for hiding this comment

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

Generator object has a method called normal()

rewards = [None] * len(results)

for i in range(len(results)):
if not results[i].exception():
Copy link

Choose a reason for hiding this comment

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

is there another spot where the exception gets logged, so we don't accidentally drop them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure what you mean by accidentally drop them. My understanding is that if there is an exception then it did not complete the task, so it is certain that there is no reward to be extracted.

Copy link

Choose a reason for hiding this comment

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

i want to see the error when the task ran, in logs. do we get that now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah I see. It is not logged at the moment but I can log the exceptions in this section

policy_obj = policy_saver.Policy.from_filesystem(tfl_dir)
return policy_obj.policy

def run_step(self, pool: FixedWorkerPool) -> None:
Copy link

Choose a reason for hiding this comment

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

do you need a docstring here? at least mention that this will block until the step is complete.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mind clarifying what you mean by block? I am not sure what it will be blocking. thanks

Copy link

Choose a reason for hiding this comment

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

i mean that there's gonna be a bunch of I/O and executions running while this waits for the responses; so it doesn't instantaneously return.

elements=[corpus.ModuleSpec(name='smth', size=1)],
additional_flags=(),
delete_flags=())
learner = blackbox_learner.BlackboxLearner(
Copy link

Choose a reason for hiding this comment

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

shouldn't at least some of these go into a setUp() method to ensure they stay unmodified across tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mind specifying what would be modified across a test? Are you saying the creation of learner_config, cps, and learner should be moved to a function defined outside of the test class which will be called inside the test class?

Copy link

Choose a reason for hiding this comment

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

write:

def setUp(self):
  super().setUp()
  self._cps = ...
  self._learner = ...

this will be executed as setup prior to every test run.

@salaast
Copy link
Collaborator Author

salaast commented Aug 9, 2023

Since these changes are applicable to blackbox_learner, they have been addressed in pr #286

Copy link
Collaborator

@mtrofin mtrofin left a comment

Choose a reason for hiding this comment

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

@ebrevdo - I'd land this as-is - it's overall fine, and it's a leaf component. Would probably want to do something with the mock worker, but can do that after. Main thing is, it has the final parts that enable es training (i.e. an actual main :) )

anything egregious I'm missing?

@ebrevdo
Copy link

ebrevdo commented Sep 18, 2023

Just nits; nothing blocking. How does this relate to #286 ?

@ebrevdo
Copy link

ebrevdo commented Sep 18, 2023

Well; the unit test setUp should maybe get fixed to avoid making it stateful?

@mtrofin
Copy link
Collaborator

mtrofin commented Sep 18, 2023

Just nits; nothing blocking. How does this relate to #286 ?

That's the library, this is the driver.

@mtrofin
Copy link
Collaborator

mtrofin commented Sep 18, 2023

Well; the unit test setUp should maybe get fixed to avoid making it stateful?

what unit test?

@mtrofin
Copy link
Collaborator

mtrofin commented Sep 22, 2023

Landing it so I can try out ES - will refactor a bunch of things shortly, which should address most of the comments here.

@mtrofin mtrofin merged commit 8d5f648 into google:main Sep 22, 2023
15 checks passed
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.

3 participants