Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Source/Cmlx/mlx/mlx/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ Compiled::Compiled(
}
}
os << "_";
for (const auto& x : inputs) {
if (constant_ids.find(x.id()) != constant_ids.end()) {
// Iterate the moved-into members; the parameters are moved-from above.
for (const auto& x : inputs_) {
if (constant_ids_.find(x.id()) != constant_ids_.end()) {
continue;
}
os << kindof(x.dtype()) << x.itemsize();
Expand Down
16 changes: 16 additions & 0 deletions Tests/MLXTests/TransformTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ class TransformTests: XCTestCase {
XCTAssertEqual(traces, 2)
}

func testCompiledKernelsDifferByInputDtype() {
// bf16 and f16 inputs upcast to float32 give the same fused graph, so
// only the input dtypes tell the two kernels apart.
let compiled = compile { (inputs: [MLXArray]) -> [MLXArray] in
let x = inputs[0].asType(.float32)
return [exp(x) * x]
}

let values = MLXArray(Array(stride(from: Float(-2), to: 2, by: 0.25)))
for dtype in [DType.bfloat16, .float16] {
let x = values.asType(dtype)
let expected = exp(values) * values
assertEqual(compiled([x])[0], expected)
}
}

class CompileTestState: CustomStringConvertible, Updatable {
var y: MLXArray
var o: MLXArray?
Expand Down
Loading