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
7 changes: 7 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ runs:
echo MLX_PTX_CACHE_DIR=/tmp/mlx-ptx-cache >> $GITHUB_ENV
fi

- name: Install Ninja on macOS
if: runner.os == 'macOS'
shell: bash
run: |
uv pip install --python .venv/bin/python --only-binary=:all: 'ninja==1.13.2'
.venv/bin/ninja --version

- name: Setup Python venv (Windows)
if: runner.os == 'Windows'
shell: cmd
Expand Down
12 changes: 11 additions & 1 deletion fork.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,14 @@ def:
- "mlx/distributed/jaccl/lib/jaccl/ring_impl.h"
- "mlx/distributed/jaccl/lib/jaccl/ring.cpp"
- "mlx/backend/metal/scaled_dot_product_attention.cpp"
- title: "CPU reductions of empty arrays"
description: |
An empty-input CPU reduction fills its output with the operation's identity
before planning a reduction. A 4 GiB output previously reached a strided
reduction whose 32-bit loop counter wrapped to zero and wrote past the buffer.
The existing large-output regression and empty-array identity tests cover this.
globs:
- "mlx/backend/cpu/reduce.cpp"
- title: "CPU qqmm refuses a global scale"
description: |
The CPU `QQMatmul` kernel has no global scale input. Upstream passes the scales to it,
Expand Down Expand Up @@ -733,7 +741,9 @@ def:
profiles of all jobs into one report. The `setup` action pins its actions to full
commit SHAs, because the organization blocks actions that are not pinned. The
organization also blocks `hendrikmuhs/ccache-action`, so `setup` installs ccache with
Homebrew and restores the ccache files with `actions/cache`. The `fork-build-cache`
Homebrew and restores the ccache files with `actions/cache`. The macOS setup
also installs pinned Ninja 1.13.2 in its Python environment, so both CMake builds
have their selected generator. The `fork-build-cache`
action saves the ccache files. It also keeps a cache of the compiled Metal kernels: the
build jobs put `metal-cache/xcrun` first in `PATH`, and that script gives the kernel
compile and link commands a cache. The key of a kernel is its preprocessed source,
Expand Down
6 changes: 6 additions & 0 deletions mlx/backend/cpu/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ void reduction_op(
array& out,
const std::vector<int>& axes,
U init) {
if (x.size() == 0) {
if (out.size() > 0) {
std::fill_n(out.data<U>(), out.size(), init);
}
return;
}
ReductionPlan plan = get_reduction_plan(x, axes);

auto in_ptr = x.data<T>();
Expand Down
10 changes: 10 additions & 0 deletions python/tests/test_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ def test_edge_case(self):
self.assertTrue(np.all(z == y))

def test_zero_size(self):
for op in ["all", "any"]:
for shape, axis in [((0,), None), ((0, 3), 0), ((3, 0), 1), ((0, 3), 1)]:
with self.subTest(op=op, shape=shape, axis=axis):
a_np = np.zeros(shape, dtype=np.bool_)
expected = getattr(np, op)(a_np, axis=axis)
actual = getattr(mx, op)(mx.array(a_np), axis=axis)
mx.eval(actual)
self.assertEqual(actual.shape, expected.shape)
self.assertEqual(actual.tolist(), expected.tolist())

# max and min have no identity, so they are only undefined when an axis
# being reduced is itself empty. An array that is empty because of some
# other axis reduces into an empty result.
Expand Down
Loading