Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions nx/lib/nx/defn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,11 @@ defmodule Nx.Defn do
end

def shard_jit_apply(fun, mesh, args, opts \\ [])
when is_function(fun) and is_list(args) and is_list(opts) do
{on_conflict, opts} = Keyword.pop(opts, :on_conflict, :raise)
when is_function(fun) and is_list(args) and is_list(opts) do
{on_conflict, opts} = Keyword.pop(opts, :on_conflict, :raise)

cond do
Nx.Defn.current() == nil ->
Nx.Defn.Compiler.current() == nil ->
do_shard_jit_apply(fun, mesh, args, opts)

on_conflict == :raise ->
Expand All @@ -870,7 +870,14 @@ defmodule Nx.Defn do
on_conflict == :reuse ->
apply(fun, args)
end
end
end

defp do_shard_jit_apply(fun, mesh, args, opts) do
opts = prepare_options(opts)
{fun, params, _templates, flatten} = Nx.Defn.Compiler.to_lazy_params(fun, args)
[res] = Nx.Defn.Compiler.__shard_jit__(fun, mesh, params, [flatten], opts)
res
end

defp compile_error!(env, description) do
raise CompileError, line: env.line, file: env.file, description: description
Expand Down
2 changes: 1 addition & 1 deletion nx/lib/nx/defn/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ defmodule Nx.Defn.Compiler do
end

def __shard_jit__(fun, mesh, params, args_list, opts) do
{module, runtime_fun, opts} = prepare_options(fun, mesh, opts)
{module, runtime_fun, opts} = prepare_options(fun, opts)
module.__shard_jit__(fun, mesh, params, runtime_fun, args_list, opts)
rescue
e in [UndefinedFunctionError] ->
Expand Down