Skip to content

feat: Add mid processors#473

Open
mc4117 wants to merge 8 commits into
mainfrom
feat/model-rollout-processors
Open

feat: Add mid processors#473
mc4117 wants to merge 8 commits into
mainfrom
feat/model-rollout-processors

Conversation

@mc4117
Copy link
Copy Markdown
Member

@mc4117 mc4117 commented Mar 26, 2026

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:

  • Added a new mid_processors section to the configuration and documentation, explaining their purpose, configuration, and use cases. [1] [2] [3]
  • Implemented the mid_processor_registry and create_mid_processor factory in src/anemoi/inference/mid_processors/__init__.py for registering and instantiating mid-processors.
  • Updated the Runner class 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]
  • Updated the ProcessorConfig type 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/

@github-project-automation github-project-automation Bot moved this to To be triaged in Anemoi-dev Mar 26, 2026
@github-actions github-actions Bot added config enhancement New feature or request labels Mar 26, 2026
@mc4117 mc4117 marked this pull request as draft March 26, 2026 17:36
Comment thread src/anemoi/inference/mid_processors/__init__.py Outdated
Comment thread src/anemoi/inference/runners/default.py Outdated
Comment thread src/anemoi/inference/runner.py Outdated
@gmertes
Copy link
Copy Markdown
Member

gmertes commented Mar 31, 2026

Could we do this with a proper hook that triggers the processor (like runner._mid_process() or something), so that updating child runners (like interpolator) is just a case of inserting the hook in the right place? And then the child runner could also turn it off if wanted, by overriding the hook.

@mc4117
Copy link
Copy Markdown
Member Author

mc4117 commented Apr 7, 2026

Could we do this with a proper hook that triggers the processor (like runner._mid_process() or something), so that updating child runners (like interpolator) is just a case of inserting the hook in the right place? And then the child runner could also turn it off if wanted, by overriding the hook.

I have changed this so it is now a hook. What do you think?

@mc4117 mc4117 marked this pull request as ready for review April 7, 2026 11:20
Comment thread src/anemoi/inference/runner.py Outdated
@HCookie HCookie force-pushed the feat/model-rollout-processors branch from 7504c36 to 362f96f Compare April 29, 2026 12:12
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Apr 29, 2026
@HCookie
Copy link
Copy Markdown
Member

HCookie commented Apr 29, 2026

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)

@ecmwf ecmwf deleted a comment from Copilot AI Apr 29, 2026
@ecmwf ecmwf deleted a comment from mc4117 Apr 29, 2026
@github-actions github-actions Bot added the tests label Apr 29, 2026
@HCookie HCookie moved this from To be triaged to Reviewers needed in Anemoi-dev Apr 29, 2026
@HCookie HCookie requested a review from gmertes April 29, 2026 12:24
@github-project-automation github-project-automation Bot moved this from Reviewers needed to For merging in Anemoi-dev Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ATS Approval not needed config documentation Improvements or additions to documentation enhancement New feature or request tests

Projects

Status: For merging

Development

Successfully merging this pull request may close these issues.

4 participants