Replies: 1 comment 2 replies
-
Yes MLX definitely supports using multiple optimizers. The simplest way is probably with the Here's a pretty bare bones example which gets at how to do this: import mlx.core as mx
import mlx.nn as nn
import mlx.optimizers as optim
o1 = optim.SGD(learning_rate=1)
o2 = optim.SGD(learning_rate=2)
opt = optim.MultiOptimizer([o1, o2], [lambda p, _: "model1" in p])
class Model(nn.Module):
def __init__(self):
super().__init__()
self.model1 = mx.array(1.0)
self.model2 = mx.array(2.0)
model = Model()
grads = {"model1": mx.array(1.0), "model2": mx.array(2.0)}
opt.update(model, grads) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a training scenario where multiple models share a single loss. I’ve implemented a custom algorithm that computes the gradients for all model parameters in a single pass (for performance reasons), and I’d like to update each model using its own optimizer.
I’d like to ask:
Does MLX support this kind of training setup?
What is the recommended way to implement this in MLX?
Are there any plans to support higher-level abstractions for multi-model training with separate optimizers?
Thank you for the great work—MLX is a pleasure to use!
Beta Was this translation helpful? Give feedback.
All reactions