{"id":27559433,"url":"https://github.com/elixir-nx/emlx","last_synced_at":"2025-05-07T08:57:44.391Z","repository":{"id":265544132,"uuid":"890418134","full_name":"elixir-nx/emlx","owner":"elixir-nx","description":"MLX Backend for Nx","archived":false,"fork":false,"pushed_at":"2025-04-27T22:11:32.000Z","size":186,"stargazers_count":117,"open_issues_count":4,"forks_count":3,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-07T08:57:36.927Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixir-nx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-18T14:33:37.000Z","updated_at":"2025-05-05T13:53:16.000Z","dependencies_parsed_at":"2024-11-29T21:38:58.399Z","dependency_job_id":null,"html_url":"https://github.com/elixir-nx/emlx","commit_stats":null,"previous_names":["elixir-nx/emlx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-nx%2Femlx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-nx%2Femlx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-nx%2Femlx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-nx%2Femlx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-nx","download_url":"https://codeload.github.com/elixir-nx/emlx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252847507,"owners_count":21813450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-20T00:02:43.590Z","updated_at":"2025-05-07T08:57:44.378Z","avatar_url":"https://github.com/elixir-nx.png","language":"Elixir","funding_links":[],"categories":["Elixir"],"sub_categories":[],"readme":"# EMLX\n\nEMLX is the Nx Backend for the [MLX](https://github.com/ml-explore/mlx) library.\n\nBecause of MLX's nature, EMLX with GPU backend is only supported on macOS. \n\nMLX with CPU backend is available on most mainstream platforms, however, the CPU backend may not be as optimized as the GPU backend, \nespecially for non-macOS OSes, as they're not prioritized for development. Right now, EMLX supports x86_64 and arm64 architectures\non both macOS and Linux.\n\nThe M-Series Macs have an unified memory architecture, which allows for more passing data between the CPU and GPU to be effectively a no-op.\n\nBesides the backend, this library also provides an Nx.Defn.Compiler implementation that allows for JIT compilation of Nx functions to MLX kernels.\nUsing this compiler is not much different from just using the default `Nx.Defn.Evaluator`, but because it sets an explicit `EMLX.eval` call,\nit allows for better caching of Nx-defined functions by MLX itself.\n\nMetal does not support 64-bit floats, so neither MLX nor EMLX do either.\n\n## Usage\n\nTo use EMLX, you can add it as a dependency in your `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:emlx, github: \"elixir-nx/emlx\", branch: \"main\"}\n  ]\nend\n```\n\nThen, you just need to set `EMLX.Backend` as the default backend for your Nx functions:\n\n```elixir\nNx.default_backend(EMLX.Backend)\n\n# Setting the device to the CPU (default)\nNx.default_backend({EMLX.Backend, device: :cpu})\n\n# Setting the device to the GPU\nNx.default_backend({EMLX.Backend, device: :gpu})\n```\n\nIf you want to use the JIT compiler, you can set the default compiler as shown below.\n\nCurrently, the underlying implementation is not totally safe and could lead to a deadlocked dirty NIF, so this must be used with care.\nDefaulting to Nx.Defn.Evaluator is the safest option for now.\n\n```elixir\nNx.Defn.default_options(compiler: EMLX)\n```\n\n### MLX binaries\n\nEMLX relies on the [MLX](https://github.com/ml-explore/mlx) library to function, and currently EMLX will download precompiled builds from [mlx-build](https://github.com/cocoa-xu/mlx-build).\n\n#### Using precompiled binaries\n\nWhile the default configuration should be suitable for most cases, there is however a number of environment variables that you may want to use in order to customize the variant of MLX binary.\n\nThe binaries are always downloaded to match the current configuration, so you should set the environment variables in .bash_profile or a similar configuration file so you don't need to export it in every shell session.\n\n##### `LIBMLX_VERSION`\n\nThe version of the MLX binary to download. By default EMLX will always use the latest version possible.\n\n##### `LIBMLX_ENABLE_JIT`\n\nDefaults to `false`.\n\nUsing JIT compilation for Metal kernels when set to `true`.\n\n##### `LIBMLX_ENABLE_DEBUG`\n\nDefaults to `false`.\n\nEnhance metal debug workflow by enabling debug information in the Metal shaders when set to `true`.\n\n##### `LIBMLX_CACHE`\n\nThe directory to store the downloaded and built archives in. Defaults to the standard cache location for the given operating system.\n\n#### Compiling from source\n\nIf you want to compile MLX from source, you can do so by setting the `LIBMLX_BUILD` environment variable to `true`.\n\nEnvironment variables listed in the previous section will still apply.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-nx%2Femlx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-nx%2Femlx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-nx%2Femlx/lists"}