Skip to content

Conversation

barronalex
Copy link
Contributor

@barronalex barronalex commented Mar 20, 2025

Builds upon #204

This PR deprecates the MLXFast, MLXFFT, MLXRandom and MLXLinalg modules.

Instead those methods are now available under the main import MLX package.

import MLXRandom
let x = key(0)

becomes:

import MLX
let x = MLXRandom.key(0)

or:

import MLX
let x = key(0)

The old way will still work, but you will now get a deprecation message.

@barronalex barronalex requested a review from davidkoski March 20, 2025 23:31
@davidkoski
Copy link
Collaborator

import MLXFFT; MLXFFT.fft()

we could potentially just implement these in MLXFFT and call the ones in MLX. That gives a place to hang the deprecation and keeps old code building.

@davidkoski
Copy link
Collaborator

This part in the docs probably needs to be updated:

though we can always pick that up after the change if needed.

import Cmlx
import Foundation

public enum MLXLinalg {
Copy link
Collaborator

@davidkoski davidkoski Mar 21, 2025

Choose a reason for hiding this comment

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

Just to make sure we like the name, these are now:

MLX.MLXLinalg.norm()

or (without the package name):

MLXLinalg.norm()

Would this look better instead?

MLX.Linalg.norm()
Linalg.norm()

I don't have a strong opinion either way. @barronalex @awni

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, but in fact we do want it the way you have it -- that means the no package version: MLXLinalg.norm() looks like the old package qualified version. I forgot :-)

Copy link
Member

@awni awni Mar 21, 2025

Choose a reason for hiding this comment

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

Can one use them as free functions or does it have to be prefixed with the enum type?

I must admit, having to use name MLXLinalg.norm everywhere is a bit unfortunate..

Copy link
Collaborator

Choose a reason for hiding this comment

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

If they are in the enum they always need the MLXLinalg.

I think we have two options there:

  • just like I suggested for FFT we leave free functions in MLXLinalg package and forward them here

  • we don't use the enum namespace here + we do the forwards from MLXLinalg

The first option let's us move to MLXLinalg.norm over time, but that assumes we want to eventually require the namespace.

The second option allows for both, though thinking about it if you import both MLX and MLXLinalg the norm function will be ambiguous and you will need to qualify it with MLXLinalg anyway. That isn't quite what we were going for. If you only import MLX it would work as expected.

///
/// ### See Also
/// - <doc:MLXFFT>
public func fft(_ array: MLXArray, n: Int? = nil, axis: Int = -1, stream: StreamOrDevice = .default)
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment in PR top level thread -- if we implement these we can:

  • put the deprecation marker on them
  • call to the new implementation in MLX to not break code that uses the old name

Base automatically changed from update-mlx-c-0.1.2 to main March 24, 2025 19:46
@barronalex barronalex merged commit 939b2ad into main Mar 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants