-
Notifications
You must be signed in to change notification settings - Fork 10
docs: Update README.md
for autogram
#410
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
8019470
to
d392656
Compare
```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() | ||
``` |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
This should be merged when we're ready to release autogram.