Repository Analysis

ml-explore/mlx

MLX: An array framework for Apple silicon

2.6 Likely human-written View on GitHub
2.6
Adjusted Score
2.6
Raw Score
100%
Time Factor
2026-05-29
Last Push
26,498
Stars
C++
Language
188,888
Lines of Code
653
Files
497
Pattern Hits
2026-05-31
Scan Date

Score History

Severity Breakdown

CRITICAL 0HIGH 8MEDIUM 11LOW 478

Pattern Findings

497 matches across 11 categories. Click a row to expand file-level details.

Hyper-Verbose Identifiers155 hits · 148 pts
SeverityFileLineSnippet
LOWsetup.py17def cuda_toolkit_major_version():
LOWpython/tests/test_fast_sdpa.py120 def test_sdpa_vector_kv_transposed_head_seq(self):
LOWpython/tests/test_fast_sdpa.py307 def test_sdpa_vector_value_dims(self):
LOWpython/tests/test_fast_sdpa.py448 def test_sdpa_long_masked_sequence(self):
LOWpython/tests/test_fast_sdpa.py501 def test_sdpa_noncontiguous_inputs(self):
LOWpython/tests/test_fast_sdpa.py556 def test_sdpa_attention_sinks(self):
LOWpython/tests/test_losses.py79 def test_binary_cross_entropy(self):
LOWpython/tests/test_losses.py138 def _test_tiny_probs_as_inputs():
LOWpython/tests/test_losses.py381 def test_cosine_similarity_loss(self):
LOWpython/tests/test_fast.py172 def test_rope_dims_validation(self):
LOWpython/tests/test_fast.py390 def test_rope_with_large_offset(self):
LOWpython/tests/test_fast.py513 def test_layer_norm_dim_check(self):
LOWpython/tests/test_fast.py610 def test_slice_into_layer_norm(self):
LOWpython/tests/test_fast.py661 def test_layer_norm_grad_no_bias(self):
LOWpython/tests/test_fast.py697 def test_layer_norm_grad_no_params(self):
LOWpython/tests/test_fast.py708 def test_layer_norm_grad_params(self):
LOWpython/tests/test_fast.py854 def test_custom_kernel_strides(self):
LOWpython/tests/test_fast.py908 def test_custom_kernel_helper(self):
LOWpython/tests/test_fast.py954 def test_custom_kernel_attributes(self):
LOWpython/tests/test_fast.py980 def test_custom_kernel_caching(self):
LOWpython/tests/test_array.py192 def test_list_not_equals_array(self):
LOWpython/tests/test_array.py215 def test_tuple_not_equals_array(self):
LOWpython/tests/test_array.py225 def test_obj_inequality_array(self):
LOWpython/tests/test_array.py385 def test_construction_from_lists(self):
LOWpython/tests/test_array.py441 def test_double_keeps_precision(self):
LOWpython/tests/test_array.py449 def test_construction_from_lists_of_mlx_arrays(self):
LOWpython/tests/test_array.py608 def test_array_repr_precision(self):
LOWpython/tests/test_array.py737 def test_array_np_dtype_conversion(self):
LOWpython/tests/test_array.py769 def test_array_from_noncontiguous_np(self):
LOWpython/tests/test_array.py776 def test_array_np_shape_dim_check(self):
LOWpython/tests/test_array.py828 def test_dtype_python_scalar_promotion(self):
LOWpython/tests/test_array.py1483 def test_array_at_slice_update_extensive(self):
LOWpython/tests/test_array.py1738 def test_np_array_conversion_copies_by_default(self):
LOWpython/tests/test_array.py1820 def test_buffer_protocol_ref_counting(self):
LOWpython/tests/test_array.py1830 def test_array_view_ref_counting(self):
LOWpython/tests/test_array.py1977 def test_inplace_preserves_ids(self):
LOWpython/tests/test_array.py1992 def test_load_from_pickled_np(self):
LOWpython/tests/test_array.py2051 def test_torch_mps_dlpack_non_cpu_error(self):
LOWpython/tests/test_array.py2127 def test_setitem_with_boolean_mask(self):
LOWpython/tests/test_array.py2164 def test_array_namespace_asarray(self):
LOWpython/tests/test_array.py2283 def test_siblings_without_eval(self):
LOWpython/tests/test_array.py2305 def test_scalar_integer_conversion_overflow(self):
LOWpython/tests/test_export_import.py134 def test_export_random_sample(self):
LOWpython/tests/test_export_import.py203 def test_export_variable_inputs(self):
LOWpython/tests/test_export_import.py272 def test_export_import_shapeless(self):
LOWpython/tests/test_export_import.py290 def test_export_scatter_gather(self):
LOWpython/tests/test_export_import.py349 def test_export_conv_shapeless(self):
LOWpython/tests/test_export_import.py466 def test_export_quantized_model(self):
LOWpython/tests/test_export_import.py488 def test_export_kwarg_ordering(self):
LOWpython/tests/test_export_import.py501 def test_export_with_callback(self):
LOWpython/tests/test_export_import.py541 def test_export_import_custom_kernel(self):
LOWpython/tests/test_export_import.py584 def test_export_import_multi_with_constants(self):
LOWpython/tests/test_export_import.py605 def test_export_import_scatter_sum(self):
LOWpython/tests/test_optimizers.py207 def test_adamw_matches_pytorch(self):
LOWpython/tests/test_optimizers.py463 def test_linear_warmup_with_cosine_decay(self):
LOWpython/tests/test_optimizers.py480 def test_compile_with_schedule(self):
LOWpython/tests/test_nn.py106 def test_save_safetensors_weights(self):
LOWpython/tests/test_nn.py252 def test_quantized_sharded_linear_construction(self):
LOWpython/tests/test_nn.py2009 def test_transformer_encoder_layer(self):
LOWpython/tests/test_nn.py2031 def test_transformer_decoder_layer(self):
95 more matches not shown…
Over-Commented Block118 hits · 118 pts
SeverityFileLineSnippet
LOWsetup.py241 }
LOWpython/src/ops.cpp1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/utils.h1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/distributed.cpp1// Copyright © 2024 Apple Inc.
LOWpython/src/transforms.cpp1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/fast.cpp1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/load.h1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/fft.cpp1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/array.cpp1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/export.cpp1// Copyright © 2024 Apple Inc.
LOWpython/src/buffer.h1// Copyright © 2024 Apple Inc.
LOWpython/src/load.cpp1// Copyright © 2023-2024 Apple Inc.
LOWpython/src/metal.cpp1// Copyright © 2023-2024 Apple Inc.
LOWtests/allocator_tests.cpp1// Copyright © 2023-2026 Apple Inc.
LOWtests/random_tests.cpp281 key = array({0u, 0u, 0u}, {3, 1});
LOWtests/autograd_tests.cpp1// Copyright © 2023 Apple Inc.
LOWexamples/extensions/axpby/axpby.cpp1// Copyright © 2023-2025 Apple Inc.
LOWmlx/mlx.h1// Copyright © 2023 Apple Inc.
LOWmlx/mlx.h21#include "mlx/random.h"
LOWmlx/ops.cpp1// Copyright © 2023-2024 Apple Inc.
LOWmlx/utils.h1// Copyright © 2023-2024 Apple Inc.
LOWmlx/transforms.cpp1// Copyright © 2023-2024 Apple Inc.
LOWmlx/threadpool.h1// This code was modified from https://github.com/progschj/ThreadPool
LOWmlx/threadpool.h21// 3. This notice may not be removed or altered from any source
LOWmlx/small_vector.h1// Copyright © 2025 Apple Inc.
LOWmlx/small_vector.h21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
LOWmlx/small_vector.h41#else
LOWmlx/small_vector.h81// Minimal SmallVector implementation. Uses inline storage first, switches to
LOWmlx/scheduler.h1// Copyright © 2023 Apple Inc.
LOWmlx/api.h1// Copyright © 2024 Apple Inc.
LOWmlx/api.h21#define MLX_API __declspec(dllexport)
LOWmlx/export.cpp1// Copyright © 2024 Apple Inc.
LOWmlx/compile.cpp1// Copyright © 2023-2024 Apple Inc.
LOWmlx/compile.cpp801 // Go through the tape in reverse order and check for fusable sub-graphs
LOWmlx/stream.cpp1// Copyright © 2026 Apple Inc.
LOWmlx/primitives.cpp1// Copyright © 2023-2024 Apple Inc.
LOWmlx/primitives.cpp5561 return {{bitwise_invert(inputs[0], stream())}, axes};
LOWmlx/primitives.cpp5581 // - dC_m = cotan [..., M, N]
LOWmlx/array.h1// Copyright © 2023 Apple Inc.
LOWmlx/graph_utils.cpp1// Copyright © 2023 Apple Inc.
LOWmlx/einsum.cpp1// Copyright © 2024 Apple Inc.
LOWmlx/distributed/jaccl/lib/jaccl/mesh_impl.h81 buff++;
LOWmlx/distributed/jaccl/lib/examples/allreduce_bench.cpp1// Copyright © 2025 Apple Inc.
LOWmlx/distributed/jaccl/lib/examples/allreduce_bench.cpp21//
LOWmlx/distributed/jaccl/lib/examples/CMakeLists.txt1cmake_minimum_required(VERSION 3.24)
LOWmlx/distributed/nccl/nccl.cpp1// NCCL distributed support currently requires Unix socket APIs
LOWmlx/distributed/mpi/mpi_declarations.h1// Copyright © 2024 Apple Inc.
LOWmlx/distributed/ring/ring.cpp1// Copyright © 2024 Apple Inc.
LOWmlx/io/load.h1// Copyright © 2023 Apple Inc.
LOWmlx/io/safetensors.cpp1// Copyright © 2023 Apple Inc.
LOWmlx/io/safetensors.cpp21#define ST_BOOL "BOOL"
LOWmlx/io/load.cpp1// Copyright © 2023-2026 Apple Inc.
LOWmlx/backend/gpu/primitives.cpp1// Copyright © 2025 Apple Inc.
LOWmlx/backend/metal/quantized.cpp1// Copyright © 2023-2024 Apple Inc.
LOWmlx/backend/metal/distributed.cpp1// Copyright © 2024 Apple Inc.
LOWmlx/backend/metal/device.h1// Copyright © 2023-2024 Apple Inc.
LOWmlx/backend/metal/matmul.cpp1// Copyright © 2023-2024 Apple Inc.
LOWmlx/backend/metal/compiled.cpp1// Copyright © 2023-2024 Apple Inc.
LOWmlx/backend/metal/hadamard.cpp1// Copyright © 2024 Apple Inc.
LOWmlx/backend/metal/indexing.cpp1// Copyright © 2023-2024 Apple Inc.
58 more matches not shown…
Unused Imports152 hits · 112 pts
SeverityFileLineSnippet
LOWpython/tests/test_fast_sdpa.py8
LOWpython/tests/test_linalg.py5
LOWpython/tests/test_conv_transpose.py5
LOWpython/tests/test_tree.py3
LOWpython/tests/test_losses.py3
LOWpython/tests/test_double.py4
LOWpython/tests/test_double.py5
LOWpython/tests/test_optimizers.py18
LOWpython/tests/test_nn.py5
LOWpython/tests/test_quantized.py3
LOWpython/tests/test_blas.py4
LOWpython/tests/test_blas.py5
LOWpython/tests/test_threads.py4
LOWpython/tests/test_reduce.py3
LOWpython/tests/test_bf16.py3
LOWpython/tests/test_bf16.py5
LOWpython/tests/test_einsum.py3
LOWpython/tests/test_autograd.py4
LOWpython/tests/test_graph.py4
LOWpython/tests/test_init.py2
LOWpython/tests/test_constants.py3
LOWpython/tests/test_vmap.py4
LOWpython/tests/test_eval.py4
LOWpython/tests/test_random.py4
LOWpython/tests/test_conv.py6
LOWpython/mlx/nn/__init__.py3
LOWpython/mlx/nn/__init__.py3
LOWpython/mlx/nn/__init__.py4
LOWpython/mlx/nn/__init__.py5
LOWpython/mlx/nn/__init__.py5
LOWpython/mlx/nn/__init__.py5
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
LOWpython/mlx/nn/layers/__init__.py3
92 more matches not shown…
Deep Nesting45 hits · 44 pts
SeverityFileLineSnippet
LOWpython/tests/test_fast_sdpa.py364
LOWpython/tests/test_fast_sdpa.py653
LOWpython/tests/test_linalg.py13
LOWpython/tests/test_linalg.py68
LOWpython/tests/test_upsample.py21
LOWpython/tests/test_fast.py368
LOWpython/tests/test_double.py115
LOWpython/tests/test_array.py1744
LOWpython/tests/test_export_import.py501
LOWpython/tests/test_export_import.py513
LOWpython/tests/test_fft.py62
LOWpython/tests/test_blas.py308
LOWpython/tests/test_blas.py485
LOWpython/tests/test_blas.py1239
LOWpython/tests/mpi_test_distributed.py31
LOWpython/tests/test_reduce.py12
LOWpython/tests/test_reduce.py29
LOWpython/tests/test_reduce.py50
LOWpython/tests/test_reduce.py86
LOWpython/tests/test_reduce.py156
LOWpython/tests/test_bf16.py127
LOWpython/tests/test_ops.py1566
LOWpython/tests/test_ops.py1633
LOWpython/tests/test_ops.py1728
LOWpython/tests/test_ops.py2364
LOWpython/tests/test_load.py40
LOWpython/tests/test_load.py90
LOWpython/tests/test_load.py131
LOWpython/tests/test_load.py303
LOWpython/tests/test_load.py341
LOWpython/mlx/nn/layers/quantized.py22
LOWpython/mlx/nn/layers/quantized.py69
LOWpython/mlx/nn/layers/base.py619
LOWpython/mlx/nn/layers/base.py649
LOWpython/mlx/nn/layers/base.py304
LOWpython/mlx/nn/layers/base.py325
LOWpython/mlx/_distributed_utils/config.py337
LOWpython/mlx/_distributed_utils/config.py486
LOWpython/mlx/_distributed_utils/config.py515
LOWpython/mlx/_distributed_utils/launch.py170
LOWpython/mlx/_distributed_utils/launch.py457
LOWpython/mlx/optimizers/optimizers.py31
LOWpython/mlx/optimizers/optimizers.py53
LOWexamples/python/qqmm.py22
LOWbenchmarks/python/hadamard_bench.py22
Docstring Block Structure4 hits · 20 pts
SeverityFileLineSnippet
HIGHpython/mlx/nn/losses.py31 Computes the cross entropy loss. Args: logits (array): The unnormalized logits. targets (array
HIGHpython/mlx/nn/losses.py127 Computes the binary cross entropy loss. By default, this function takes the pre-sigmoid logits, which results
HIGHpython/mlx/nn/losses.py565 Calculate the margin ranking loss that loss given inputs :math:`x_1`, :math:`x_2` and a label :math:`y` (contai
HIGHpython/mlx/nn/layers/linear.py80Return a quantized approximation of this layer. If ``quantize_input`` is ``False``, returns a :obj:`QuantizedLi
Cross-Language Confusion4 hits · 16 pts
SeverityFileLineSnippet
HIGHpython/mlx/_distributed_utils/launch.py159 script += "if ps -p $pid >/dev/null; then "
HIGHpython/mlx/_distributed_utils/common.py51 {"ssh": "hostname1", "ips": ["123.123.123.1"], "rdma": [null, "rdma_en2", "rdma_en3"]},
HIGHpython/mlx/_distributed_utils/common.py52 {"ssh": "hostname2", "ips": ["123.123.123.2"], "rdma": ["rdma_en2", null, "rdma_en3"]},
HIGHpython/mlx/_distributed_utils/common.py54 {"ssh": "hostnameN", "ips": ["123.123.123.N"], "rdma": ["rdma_en2", "rdma_en3", null]},
Dead Code7 hits · 14 pts
SeverityFileLineSnippet
MEDIUMpython/tests/test_einsum.py192
MEDIUMpython/tests/test_einsum.py193
MEDIUMpython/tests/test_einsum.py195
MEDIUMpython/tests/test_einsum.py196
MEDIUMpython/tests/test_einsum.py197
MEDIUMpython/tests/test_einsum.py198
MEDIUMpython/tests/test_einsum.py199
Self-Referential Comments3 hits · 9 pts
SeverityFileLineSnippet
MEDIUMpython/mlx/utils.py161 # Create the function to update the destination. We are taking advantage of
MEDIUMpython/mlx/_distributed_utils/config.py256 # Create a reverse index to be able to map uuids to (host, port) quickly
MEDIUMpython/src/stream.cpp158 # Create a context manager for the default device and stream.
Redundant / Tautological Comments5 hits · 8 pts
SeverityFileLineSnippet
LOWsetup.py134 # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
LOWpython/tests/test_constants.py12 # Check if mlx constants match expected values
LOWpython/tests/test_constants.py25 # Check if mlx constants are available
LOWpython/mlx/extension.py53 # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
LOWpython/mlx/_distributed_utils/launch.py267 # Check if all are running and terminate otherwise
Excessive Try-Catch Wrapping3 hits · 3 pts
SeverityFileLineSnippet
LOWpython/mlx/_distributed_utils/common.py85 except Exception as e:
LOWbenchmarks/python/masked_scatter.py36 except Exception:
LOWbenchmarks/python/masked_scatter.py45 except Exception:
AI Slop Vocabulary1 hit · 3 pts
SeverityFileLineSnippet
MEDIUMmlx/distributed/jaccl/lib/jaccl/rdma.h337 // Twice has proven to be more robust to initialization issues.