Skip to content

[Feature Request] Add support for custom conflict-resolution hooks in gradient aggregation #775

Description

It would be great to have a clear hook/extension point in TorchJD that allows users to pass custom gradient transformation or conflict-resolution logic directly during the optimization step.

Currently, implementing experimental or non-standard gradient aggregation strategies requires either modifying core library functions or wrapping existing optimizers in a non-standard way.

When experimenting with multi-task learning models, researchers often need to test custom heuristics for resolving conflicting gradients (e.g., dynamic gradient scaling, specialized projection masks, or combining multiple conflict-resolution algorithms).

Having a clean, modular API hook for custom gradient transformations would make TorchJD much more flexible for prototyping new multi-task optimization research without needing to fork the repository.

cc @PierreQuinton @ValerianRey @ppraneth

Ideally, the API could accept a custom callable or transformer module:

import torch
import torchjd

def custom_gradient_transform(matrix: torch.Tensor) -> torch.Tensor:
    # Custom transformation / projection logic on the task gradient matrix
    return updated_matrix

# Pass custom transformation logic into the optimizer or step wrapper
optimizer = torchjd.optim.MinimalCostBinding(
    model.parameters(), 
    transform_fn=custom_gradient_transform
)

This would make it easier to benchmark custom multi-task algorithms against standard methods like PCGrad or CAGrad.

Happy to help draft a PR or discuss the design further if this fits into the project roadmap!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions