-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add better errors for invalid compiler configurations (#1575)
Co-authored-by: José Valim <[email protected]>
- Loading branch information
1 parent
c83c4a0
commit aa366da
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule Nx.Defn.CompilerTest do | ||
use ExUnit.Case, async: true | ||
|
||
defmodule SomeInvalidServing do | ||
def init(_, _, _) do | ||
:ok | ||
end | ||
end | ||
|
||
test "raises an error if the __compile__ callback is missing" do | ||
msg = | ||
"the expected compiler callback __compile__/4 is missing. Please check that the module SomeInvalidCompiler is an Nx.Defn.Compiler." | ||
|
||
assert_raise ArgumentError, msg, fn -> | ||
Nx.Defn.compile(&Function.identity/1, [Nx.template({}, :f32)], | ||
compiler: SomeInvalidCompiler | ||
) | ||
end | ||
end | ||
|
||
test "raises an error if the __jit__ callback is missing" do | ||
msg = | ||
"the expected compiler callback __jit__/5 is missing. Please check that the module SomeInvalidCompiler is an Nx.Defn.Compiler." | ||
|
||
assert_raise ArgumentError, msg, fn -> | ||
Nx.Defn.jit(&Function.identity/1, compiler: SomeInvalidCompiler).(1) | ||
end | ||
end | ||
|
||
test "raises an error if the __partitions_options__ callback is missing" do | ||
msg = | ||
"the expected compiler callback __partitions_options__/1 is missing. Please check that the module SomeInvalidCompiler is an Nx.Defn.Compiler." | ||
|
||
serving = Nx.Serving.new(SomeInvalidServing, [], compiler: SomeInvalidCompiler) | ||
|
||
assert_raise ArgumentError, msg, fn -> | ||
Nx.Serving.init({MyName, serving, true, [1], 10, 1000, nil, 1}) | ||
end | ||
end | ||
|
||
test "raises an error if the __to_backend__ callback is missing" do | ||
msg = | ||
"the expected compiler callback __to_backend__/1 is missing. Please check that the module SomeInvalidCompiler is an Nx.Defn.Compiler." | ||
|
||
assert_raise ArgumentError, msg, fn -> | ||
Nx.Defn.to_backend(compiler: SomeInvalidCompiler) | ||
end | ||
end | ||
end |