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

Fix/async callbacks #102

Open
wants to merge 105 commits into
base: develop
Choose a base branch
from
Open

Fix/async callbacks #102

wants to merge 105 commits into from

Conversation

mc4117
Copy link
Member

@mc4117 mc4117 commented Oct 23, 2024

Adding asynchronous callbacks and scatter plots following the former PR by @anaprietonem in aifs-mono (https://github.com/ecmwf-lab/aifs-mono/pull/230/files#diff-817e70e1a151825208d5b55a0b204d08abe52afb9b675b60c48e85376357cc92)

HCookie and others added 30 commits September 24, 2024 09:44
- Split into seperate files
- Use list in config to add callbacks
- Provide legacy config enabled approach
- Fix ruff issues
- Prefill config with callbacks
- Warn on deprecations for old config
- Expand config enabled
- Add back SWA
- Fix logging callback
- Add flag to disable checkpointing
- Add testing
[feature] Fix trainable attribute callbacks
- Split plots
- Rename, lr to optimiser
- Refactor plotting callbacks to be more init config
- Remove enabled from plotting callbacks
- Connect sample_idx in config
Refactor rollout logic
CHANGELOG.md Show resolved Hide resolved
src/anemoi/training/diagnostics/callbacks/plot.py Outdated Show resolved Hide resolved
self._plot_with_error_catching,
trainer,
*args,
*kwargs.values(),
Copy link
Member

Choose a reason for hiding this comment

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

This implies that kwargs will be provided in the correct order?
Why can't this be expanded normally?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe something like this ?

def func(s, trainer, args, kwargs):
  return s._plot_with_error_catching(trainer, *args, **kwargs)
  
await loop.run_in_executor(
             self._executor,
             func,
             self,
             trainer,
             args,
             kwargs,

I am not sure we need to pass self as an argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I had a better look into this. And what's happening is that the async function run_in_executor doesn't support keyword arguments, so using *kwargs.values() bypasses the need to pass keywords directly by transforming the keyword arguments into positional ones. In that way the values are then correctly used by _plot_with_error_catching as positional arguments, which matches the signature that accepts *args.
I have updated the code to reflect that! happy to discuss further!

Copy link
Member

Choose a reason for hiding this comment

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

Let's discuss, I do like Florian's suggestion, it helps ensure that the kwargs are used correctly.

src/anemoi/training/diagnostics/maps.py Outdated Show resolved Hide resolved
src/anemoi/training/diagnostics/plots.py Outdated Show resolved Hide resolved
@HCookie HCookie changed the base branch from fxi/refactor_callbacks to develop October 29, 2024 13:17
@mc4117 mc4117 changed the title [draft] Fix/async callbacks Fix/async callbacks Oct 29, 2024
CHANGELOG.md Show resolved Hide resolved
self._plot_with_error_catching,
trainer,
*args,
*kwargs.values(),
Copy link
Member

Choose a reason for hiding this comment

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

Let's discuss, I do like Florian's suggestion, it helps ensure that the kwargs are used correctly.

Comment on lines +180 to 183
trainer,
*args,
**kwargs,
) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Missing type hints

Suggested change
trainer,
*args,
**kwargs,
) -> None:
trainer: pl.Trainer,
*args: Any,
**kwargs: Any,
) -> None:

Comment on lines +165 to +166
async def submit_plot(self, trainer, *args, **kwargs) -> None:
"""Async function or coroutine to schedule the plot function."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
async def submit_plot(self, trainer, *args, **kwargs) -> None:
"""Async function or coroutine to schedule the plot function."""
async def submit_plot(self, trainer: pl.Trainer, *args: Any, **kwargs: Any) -> None:
"""Async function or coroutine to schedule the plot function."""

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.

6 participants