Conversation
The regex in test_mlx_imports_stay_inside_the_backend required a space or a dot right after "mlx", so "from mlx_lm.models... import ..." never matched and the guard silently passed framework code that imports mlx_lm directly. Tighten the pattern to "(from|import)\s+mlx(?:_lm)?\b". The stricter guard immediately flags src/edge0/streaming/layer.py:49, which imports _gather_sort / _scatter_unsort from mlx_lm.models.switch_layers. Rather than turn CI red, that file is listed in an explicit _MLX_IMPORT_KNOWN_VIOLATIONS set with a note on what should move into the framework; remove the entry once the helpers no longer come from mlx_lm. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
tests/test_repo_hygiene.py::test_mlx_imports_stay_inside_the_backendenforces the rule stated inbackends/__init__.py: MLX packages are imported only underedge0/backends/mlx/. Its regex requires a space or a dot right aftermlx, sofrom mlx_lm.models... import ...never matches and the guard silently passes framework code that importsmlx_lmdirectly.This PR tightens the pattern to
^\s*(?:from|import)\s+mlx(?:_lm)?\b.What it finds
The stricter guard immediately flags
src/edge0/streaming/layer.py:49:Rather than turn CI red on an existing file, that path is listed in an explicit
_MLX_IMPORT_KNOWN_VIOLATIONSset with a note on what should move into the framework. Remove the entry once the two helpers no longer come frommlx_lm. I'm happy to send that follow-up: they are a few lines of argsort/gather that can live next tomoe/routing.py, which would also make the streaming layer importable on a non-MLX backend.If you would rather have the guard fail loudly instead, drop the allowlist — the regex change alone is the fix.
Checks
pytest tests/test_repo_hygiene.py— 4 passed. The file imports nothing fromedge0ormlx, so this runs on any platform, same as the existing Linux hygiene job.import mlx,import mlx.core as mx,from mlx_lm import x,from mlx_lm.models.base import ..., and does not matchfrom edge0.backends.mlx._impl import ...or a hypotheticalmlxfoopackage.Context
I'm working on a CUDA/PyTorch backend for the reserved
backends/cuda/slot (https://github.com/smartbulldog-pro/edge0-cuda/tree/cuda-backend). This import is the one thing that keepsstreaming/layer.pyfrom importing on a non-MLX backend, which is how I ran into the guard.