Accept :hooks compiler opt in EMLX.__compile__/4 - #133
Merged
polvalente merged 3 commits intoAug 12, 2026
Conversation
nx's `Nx.Defn.compile/3`/`jit/2` now always forward a `:hooks` option
(defaulting to `%{}`) to the selected compiler, even when no hooks are
used. EMLX's strict Keyword.validate! allowlist didn't include it, so
any compile under a current nx (e.g. bench/svd_bench.exs, which pins
nx main) failed immediately with "unknown keys [:hooks]".
An empty hooks map is now accepted and ignored. A non-empty one raises
a clear error instead: EMLX lowers :hook/:io_call expr nodes natively
(each with its own inline default callback), but doesn't wire through
the named-override map carried by this compiler opt.
polvalente
reviewed
Aug 12, 2026
Comment on lines
+1741
to
+1752
| # Known EMLX-specific compiler opts. `:command_queue` is injected by | ||
| # `__partitions_options__/1` but may also be passed directly by callers | ||
| # that manage their own queues (equivalent to a manual `with_queue`). | ||
| @valid_compiler_keys [:device, :max_concurrency, :command_queue] | ||
| # | ||
| # `:hooks` isn't EMLX-specific — `Nx.Defn.compile/3`/`jit/2` always forward | ||
| # it (defaulting to `%{}`) to whichever compiler is selected (see | ||
| # `Nx.Defn.prepare_options/1`), so every `Nx.Defn.Compiler` callback must | ||
| # accept it even if unused. `:hook`/`:io_call` *expr nodes* (each carrying | ||
| # their own inline default callback) do lower natively — see | ||
| # `EMLX.Native.Expr`'s `:hook`/`:io_call` clause — but the *named-override* | ||
| # map this option carries (swapping in a different callback per hook name | ||
| # at compile time) isn't wired through, so it's only accepted when empty. |
Collaborator
There was a problem hiding this comment.
Let's remove these comments
polvalente
reviewed
Aug 12, 2026
Comment on lines
+1785
to
+1795
| case Keyword.get(opts, :hooks, %{}) do | ||
| empty when empty == %{} -> | ||
| :ok | ||
|
|
||
| hooks -> | ||
| raise ArgumentError, | ||
| "EMLX does not support the :hooks named-override map (got callbacks for " <> | ||
| "#{inspect(Map.keys(hooks))}) — :hook/:io_call expr nodes lower natively " <> | ||
| "with their own inline default callback, but swapping in a different " <> | ||
| "callback per hook name via compiler opts isn't wired through" | ||
| end |
Collaborator
There was a problem hiding this comment.
I believe we should add support for them. Can you either implement this (bigger ask) or open a related issue?
Contributor
Author
There was a problem hiding this comment.
I think we can open an issue for this now. I can pick it up later.
nx's `Nx.Defn.compile/3`/`jit/2` now always forward a `:hooks` option
(defaulting to `%{}`) to the selected compiler, even when no hooks are
used. EMLX's strict Keyword.validate! allowlist didn't include it, so
any compile under a current nx (e.g. bench/svd_bench.exs, which pins
nx main) failed immediately with "unknown keys [:hooks]".
An empty hooks map is now accepted and ignored. A non-empty one raises
a clear error instead: EMLX lowers :hook/:io_call expr nodes natively
(each with its own inline default callback), but doesn't wire through
the named-override map carried by this compiler opt.
…mlx into fix/compiler-hooks-opt
polvalente
approved these changes
Aug 12, 2026
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.
nx's
Nx.Defn.compile/3/jit/2now always forward a:hooksoption (defaulting to%{}) to the selected compiler, even when no hooks are used. EMLX's strict Keyword.validate! allowlist didn't include it, so any compile under a current nx (e.g. bench/svd_bench.exs, which pins nx main) failed immediately with "unknown keys [:hooks]".An empty hooks map is now accepted and ignored. A non-empty one raises a clear error instead: EMLX lowers :hook/:io_call expr nodes natively (each with its own inline default callback), but doesn't wire through the named-override map carried by this compiler opt.