feat: Add mid processors#473
Open
mc4117 wants to merge 8 commits into
Open
Conversation
mc4117
commented
Mar 26, 2026
mc4117
commented
Mar 26, 2026
mc4117
commented
Mar 26, 2026
Member
|
Could we do this with a proper hook that triggers the processor (like |
Member
Author
I have changed this so it is now a hook. What do you think? |
mc4117
commented
Apr 10, 2026
- Add a hook for middle of rollout processors
7504c36 to
362f96f
Compare
Member
|
To fix your steady state issues, you could do something like follow: from torch import Tensor
from anemoi.inference.config.run import RunConfiguration
from anemoi.inference.runner import Runner
from anemoi.inference.runner import RunnerClasses
from anemoi.inference.tensors import TensorHandler
class SteadyStateTensorHandler(TensorHandler):
def add_dynamic_forcings_to_input_tensor(self, input_tensor_torch: Tensor, *_, **__) -> Tensor:
return input_tensor_torch
STEADY_STATE_CLASSES = RunnerClasses(
tensor_handler=SteadyStateTensorHandler
)
class SteadyStateRunner(Runner):
"""A runner that does not perform any model inference, but simply copies the input to the output at each step. This is useful for testing purposes."""
def __init__(self, config: RunConfiguration, *, classes: RunnerClasses | None = None) -> None:
super().__init__(config, classes=STEADY_STATE_CLASSES) |
gmertes
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces support for "mid-processors" in the inference pipeline, allowing users to specify processors that are applied after each inference step and before the next input is prepared. This enables efficient, in-place modifications of model state while tensors are still on the GPU. The changes span documentation, configuration, implementation, and tests.
Mid-processor support:
mid_processorssection to the configuration and documentation, explaining their purpose, configuration, and use cases. [1] [2] [3]mid_processor_registryandcreate_mid_processorfactory insrc/anemoi/inference/mid_processors/__init__.pyfor registering and instantiating mid-processors.Runnerclass to support per-dataset mid-processors: added creation (create_mid_processors), application (_apply_mid_processors), and integration into the inference loop to modify state and update predictions as needed. [1] [2] [3] [4] [5] [6]ProcessorConfigtype to clarify it now also applies to mid-processors.What problem does this change solve?
This is needed for dynamical tests where we would like to subtract the tendency from each forecast step for example
As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/
By opening this pull request, I affirm that all authors agree to the Contributor License Agreement.
📚 Documentation preview 📚: https://anemoi-inference--473.org.readthedocs.build/en/473/