Skip to content

Conversation

ValerianRey
Copy link
Contributor

@ValerianRey ValerianRey commented Aug 31, 2025

This should be merged when we're ready to release autogram.

Copy link

codecov bot commented Aug 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValerianRey ValerianRey changed the title autogram readme docs: Update README.md for autogram Aug 31, 2025
@ValerianRey ValerianRey added the docs Improvements or additions to documentation label Aug 31, 2025
Comment on lines +125 to +156
```diff
import torch
from torch.nn import Linear, MSELoss, ReLU, Sequential
from torch.optim import SGD

+ from torchjd.autogram import Engine
+ from torchjd.aggregation import UPGradWeighting

model = Sequential(Linear(10, 5), ReLU(), Linear(5, 3), ReLU(), Linear(3, 1), ReLU())

- loss_fn = MSELoss()
+ loss_fn = MSELoss(reduction="none")
optimizer = SGD(model.parameters(), lr=0.1)

+ weighting = UPGradWeighting()
+ engine = Engine(model.modules())

inputs = torch.randn(8, 16, 10) # 8 batches of 16 random input vectors of length 10
targets = torch.randn(8, 16) # 8 batches of 16 targets for the first task

for input, target in zip(inputs, targets):
output = model(input).squeeze(dim=1) # shape [16]
- loss = loss_fn(output, target) # shape [1]
+ losses = loss_fn(output, target) # shape [16]

optimizer.zero_grad()
- loss.backward()
+ gramian = engine.compute_gramian(losses) # shape: [16, 16]
+ weights = weighting(gramian) # shape: [16]
+ losses.backward(weights)
optimizer.step()
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be the most important example after #411 ?

Copy link
Contributor Author

@ValerianRey ValerianRey Sep 1, 2025

Choose a reason for hiding this comment

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

A bit early to say. Depends on what we want people to do with our library. It may be good to start with this example and to have a more complex one after. To have like:

  • MTL with autojac
  • IWRM with autogram
  • MTL + IWRM with autogram

I think it's always much easier to have the simpler things come first and complexify after, even if what we want people to do is the complex stuff.

This is just the state of the README as it was in #387 btw, nothing new in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants