Skip to content

Commit 9e3452e

Browse files
committed
Use EXLA for Nx backend
1 parent 4fd48ed commit 9e3452e

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

config/test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ import Config
33
config :logger,
44
level: :warning
55

6+
# Route all Nx.Defn computations (including Bumblebee featurizer
7+
# preprocessing) through EXLA. This includes Apple Silicon — EXLA's
8+
# XLA CPU path uses NEON/AMX and is significantly faster than the
9+
# pure-Elixir Nx.Defn.Evaluator for both preprocessing and inference.
610
config :nx, :default_defn_options, [compiler: EXLA]

lib/classification.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,8 @@ if ImageVision.bumblebee_configured?() do
271271
end
272272

273273
# Use EXLA as the Nx compiler when it is properly loaded and implements
274-
# the current Nx.Defn.Compiler protocol. Falls back to the default
275-
# evaluator when EXLA is absent or version-mismatched (e.g. EXLA 0.10
276-
# paired with Nx 0.11 does not export __compile__/4).
274+
# the current Nx.Defn.Compiler protocol. Falls back to the configured
275+
# default (or Nx.Defn.Evaluator) when EXLA is absent or mismatched.
277276
defp defn_options do
278277
if Code.ensure_loaded?(EXLA) and function_exported?(EXLA, :__compile__, 4) do
279278
[compiler: EXLA]

mix.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ defmodule ImageVision.MixProject do
6161
# These are declared `optional: true` so downstream consumers
6262
# must opt in explicitly. `image_vision` itself does not pull
6363
# them into the dependency graph, letting applications choose
64-
# their preferred backend (EXLA for CPU/GPU, etc.) and their
65-
# own Bumblebee version.
64+
# their preferred backend and Bumblebee version.
6665
#
6766
# * Segmentation (`Image.Segmentation`) and object detection
6867
# (`Image.Detection`) run ONNX models via Ortex.
6968
{:ortex, "~> 0.1", optional: true},
7069
#
7170
# * Classification (`Image.Classification`) and embedding
7271
# (`Image.Classification.embed/2`) use Bumblebee servings.
73-
# Users must separately add `:exla` (or another Nx compiler)
74-
# to their own `mix.exs` for the actual Nx backend at runtime.
72+
# Users must separately add an Nx compiler to their own `mix.exs`.
7573
{:nx, "~> 0.11", optional: true, override: true},
7674
{:nx_image, "~> 0.1", optional: true},
7775
{:bumblebee, "~> 0.6", optional: true},
76+
# EXLA provides XLA-backed Nx.Defn compilation. Works on all
77+
# platforms including Apple Silicon (via XLA's CPU/NEON/AMX path).
7878
{:exla, "~> 0.11", optional: true},
7979

8080
# --- Tooling ---

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dialyxir": {:hex, :dialyxir, "1.4.7", "dda948fcee52962e4b6c5b4b16b2d8fa7d50d8645bbae8b8685c3f9ecb7f5f4d", [:mix], [{:erlex, ">= 0.2.8", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b34527202e6eb8cee198efec110996c25c5898f43a4094df157f8d28f27d9efe"},
1111
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
1212
"elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"},
13+
"emily": {:hex, :emily, "0.3.2", "6eccc28a62b0a08628e50ce79034d36da71e78c3c24dafbd5cf20ae880899a08", [:mix], [{:axon, "~> 0.7", [hex: :axon, repo: "hexpm", optional: true]}, {:bumblebee, "~> 0.6", [hex: :bumblebee, repo: "hexpm", optional: true]}, {:elixir_make, "~> 0.9", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.1", [hex: :fine, repo: "hexpm", optional: false]}, {:nx, "~> 0.10", [hex: :nx, repo: "hexpm", optional: false]}, {:tokenizers, "~> 0.5", [hex: :tokenizers, repo: "hexpm", optional: true]}], "hexpm", "74e876a0dde427d021f7685f5b7d0679eb41861d48993c2bf9fdc7adc1104b2a"},
1314
"erlex": {:hex, :erlex, "0.2.8", "cd8116f20f3c0afe376d1e8d1f0ae2452337729f68be016ea544a72f767d9c12", [:mix], [], "hexpm", "9d66ff9fedf69e49dc3fd12831e12a8a37b76f8651dd21cd45fcf5561a8a7590"},
1415
"ex_doc": {:hex, :ex_doc, "0.40.1", "67542e4b6dde74811cfd580e2c0149b78010fd13001fda7cfeb2b2c2ffb1344d", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "bcef0e2d360d93ac19f01a85d58f91752d930c0a30e2681145feea6bd3516e00"},
1516
"exla": {:hex, :exla, "0.11.0", "1428de9edcb297480a64611d3a72fcefe13c93c115bba6d38e910583c37e38c8", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.1", [hex: :fine, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:nx, "~> 0.11.0", [hex: :nx, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xla, "~> 0.10.0", [hex: :xla, repo: "hexpm", optional: false]}], "hexpm", "1067207c802bd6f28cded6a2664979ee2e25dddce95cb84be3f0a3ebfbab2c74"},

0 commit comments

Comments
 (0)