Skip to content

Conversation

@Joannis
Copy link

@Joannis Joannis commented Dec 1, 2025

Based on #293

Proposed changes

  • Linux compilation works.
  • Doesn't support cross-compilation yet

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@Joannis Joannis marked this pull request as ready for review December 1, 2025 15:39
@incertum
Copy link
Contributor

incertum commented Dec 1, 2025

Amazing @Joannis! Let me check in with @davidkoski and ask when we might be ready to bump mlx-c in order to unblock current PRs.

@Joannis Joannis force-pushed the update/support-linux-native-build-cmake-cpu-backend branch 2 times, most recently from 878fc10 to e8dd62b Compare December 1, 2025 18:20
@incertum
Copy link
Contributor

incertum commented Dec 2, 2025

@Joannis you may rebase this PR now since the other PR got merged yesterday. Happy to help with the review once it's rebased.

incertum and others added 3 commits December 18, 2025 21:36
Signed-off-by: Melissa Kilby <mkilby@apple.com>

# Conflicts:
#	CMakeLists.txt
#	README.md
#	Source/Examples/Example1.swift
#	Source/Examples/Tutorial.swift
@Joannis Joannis force-pushed the update/support-linux-native-build-cmake-cpu-backend branch from e8dd62b to 76494af Compare December 18, 2025 20:38
@Joannis
Copy link
Author

Joannis commented Dec 18, 2025

Rebased @incertum

@incertum
Copy link
Contributor

incertum commented Dec 18, 2025

Rebased @incertum

wohoo, could you run pre-commit run --all and re-push?

This commit should not exist f85906c after a clean rebase (since you worked on top of the previous PR). You could cherry delete it and or perhaps retry the rebase? Thanks a bunch!

}

open func callAsFunction(_ x: MLXArray) -> MLXArray {
#if canImport(MLXFast)
Copy link
Contributor

Choose a reason for hiding this comment

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

@davidkoski do you have more context around MLXFast issues? Intuitively it sounds like something you would like to have. It seems to just compile fine over CMake on Linux.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure what this is for. MLXFast used to be a separate package, but was folded into MLX, see Sources/MLX/MLXFast.swift.

MLXFast remains as a stub to avoid breaking things and this function is:

@available(*, deprecated, message: "layerNorm is now available in the main MLX module")
@_disfavoredOverload
public func layerNorm(
    _ x: MLXArray, weight: MLXArray? = nil, bias: MLXArray? = nil, eps: Float,
    stream: StreamOrDevice = .default
) -> MLXArray {
    return MLXFast.layerNorm(x, weight: weight, bias: bias, eps: eps, stream: stream)
}

What issue is this working around?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case MLXFast is an enum to give a namespace to look like the old module MLXFast. So we have:

  • MLXFast.layerNorm (the module MLXFast if you were to import that)
  • MLX.MLXFast.layerNorm aka MLXFast.layerNorm (the new home, you should not import MLXFast and it is not here)
  • MLX.layerNorm (just forwards to MLX.MLXFast.layerNorm for convenience)

OK, so the code here is referencing the second one as there is no import of MLXFast, thus we are getting the MLXFast scoped to the MLX module.

@@ -0,0 +1,24 @@
FROM swift:6.2.1-jammy AS base
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we move the Dockerfile somewhere under .github for CI use or for documentation purposes?

How much work would it be to add the swift build to https://github.com/ml-explore/mlx-swift/blob/main/.github/scripts/setup%2Bbuild-linux-container-cmake.sh

or better yet a new script / CI job (my preference)?

dependencies: [
"MLX",
"MLXRandom",
.target(name: "MLXFast", condition: .when(platforms: [.macOS, .iOS, .tvOS, .visionOS, .watchOS]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these references to MLXFast are:

  1. stale
  2. maybe causing the problems in Normalization.swift. I propose the following:
diff --git a/Package.swift b/Package.swift
index d88d9e4..0d1ed11 100644
--- a/Package.swift
+++ b/Package.swift
@@ -188,7 +188,7 @@ let package = Package(
         ),
         .target(
             name: "MLXNN",
-            dependencies: ["MLX", "MLXRandom", "MLXFast"],
+            dependencies: ["MLX"],
             swiftSettings: [
                 .enableExperimentalFeature("StrictConcurrency")
             ]
@@ -218,7 +218,7 @@ let package = Package(
         .testTarget(
             name: "MLXTests",
             dependencies: [
-                "MLX", "MLXRandom", "MLXNN", "MLXOptimizers", "MLXFFT", "MLXLinalg", "MLXFast",
+                "MLX", "MLXNN", "MLXOptimizers",
             ]
         ),
 

@davidkoski
Copy link
Collaborator

FYI #319 will have more Package.swift changes -- if we can get this merged first you won't have to figure out how to merge those in.

Outstanding issues. These have to be fixed before the merge:

  • swift-format
  • figure out this MLXFast issue
  • move Dockerfile under .github

Ideally this would be fixed but we can do a followup PR:

  • integrate swift build into GitHub actions

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