mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-26 02:33:21 +08:00
recompile when shapeless is different (#1776)
This commit is contained in:
parent
a8666a757a
commit
90532b1f37
@ -197,8 +197,10 @@ std::uintptr_t get_function_address(const std::function<T(U...)>& fun) {
|
|||||||
class CompilerCache {
|
class CompilerCache {
|
||||||
public:
|
public:
|
||||||
struct CacheEntry {
|
struct CacheEntry {
|
||||||
CacheEntry(Stream stream) : stream(stream) {};
|
CacheEntry(Stream stream, bool shapeless)
|
||||||
|
: stream(stream), shapeless(shapeless) {};
|
||||||
Stream stream;
|
Stream stream;
|
||||||
|
bool shapeless;
|
||||||
std::vector<array> inputs;
|
std::vector<array> inputs;
|
||||||
std::vector<array> outputs;
|
std::vector<array> outputs;
|
||||||
std::vector<array> tape;
|
std::vector<array> tape;
|
||||||
@ -245,6 +247,9 @@ class CompilerCache {
|
|||||||
if (entry.stream != stream) {
|
if (entry.stream != stream) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (entry.shapeless != shapeless) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check the inputs match and return if so
|
// Check the inputs match and return if so
|
||||||
if (has_same_shape_and_dtype(inputs, entry.inputs) &&
|
if (has_same_shape_and_dtype(inputs, entry.inputs) &&
|
||||||
@ -253,7 +258,7 @@ class CompilerCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise append a new cache entry
|
// Otherwise append a new cache entry
|
||||||
entries.push_back(CacheEntry{stream});
|
entries.push_back(CacheEntry{stream, shapeless});
|
||||||
return entries.back();
|
return entries.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,6 +675,10 @@ class TestCompile(mlx_tests.MLXTestCase):
|
|||||||
def mean(x):
|
def mean(x):
|
||||||
return mx.mean(x, keepdims=True)
|
return mx.mean(x, keepdims=True)
|
||||||
|
|
||||||
|
cfun = mx.compile(mean)
|
||||||
|
out = cfun(mx.ones((5, 5)))
|
||||||
|
self.assertTrue(mx.allclose(out, mx.array(1.0)))
|
||||||
|
|
||||||
cmean = mx.compile(mean, shapeless=True)
|
cmean = mx.compile(mean, shapeless=True)
|
||||||
|
|
||||||
x = mx.ones(2)
|
x = mx.ones(2)
|
||||||
|
Loading…
Reference in New Issue
Block a user