-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from LuxDL/ap/fixes
Inefficient matmul version of DeepONet
- Loading branch information
Showing
7 changed files
with
98 additions
and
98 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
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 |
---|---|---|
@@ -1,35 +1,48 @@ | ||
@testitem "DeepONet" setup=[SharedTestSetup] begin | ||
@testset "BACKEND: $(mode)" for (mode, aType, dev, ongpu) in MODES | ||
rng_ = get_stable_rng() | ||
rng = StableRNG(12345) | ||
|
||
u = rand(64, 5) |> aType # sensor_points x nb | ||
y = rand(1, 10, 5) |> aType # ndims x N x nb | ||
u = rand(Float32, 64, 5) |> aType # sensor_points x nb | ||
y = rand(Float32, 1, 10, 5) |> aType # ndims x N x nb | ||
out_size = (10, 5) | ||
|
||
don_ = DeepONet(; branch=(64, 32, 32, 16), trunk=(1, 8, 8, 16)) | ||
deeponet = DeepONet(; branch=(64, 32, 32, 16), trunk=(1, 8, 8, 16)) | ||
|
||
ps, st = Lux.setup(rng_, don_) |> dev | ||
ps, st = Lux.setup(rng, deeponet) |> dev | ||
|
||
@inferred don_((u, y), ps, st) | ||
@jet don_((u, y), ps, st) | ||
@inferred deeponet((u, y), ps, st) | ||
@jet deeponet((u, y), ps, st) | ||
|
||
pred = first(don_((u, y), ps, st)) | ||
pred = first(deeponet((u, y), ps, st)) | ||
@test size(pred) == out_size | ||
|
||
don_ = DeepONet(Chain(Dense(64 => 32), Dense(32 => 32), Dense(32 => 16)), | ||
deeponet = DeepONet(Chain(Dense(64 => 32), Dense(32 => 32), Dense(32 => 16)), | ||
Chain(Dense(1 => 8), Dense(8 => 8), Dense(8 => 16))) | ||
|
||
ps, st = Lux.setup(rng_, don_) |> dev | ||
ps, st = Lux.setup(rng, deeponet) |> dev | ||
|
||
@inferred don_((u, y), ps, st) | ||
@jet don_((u, y), ps, st) | ||
@inferred deeponet((u, y), ps, st) | ||
@jet deeponet((u, y), ps, st) | ||
|
||
pred = first(don_((u, y), ps, st)) | ||
pred = first(deeponet((u, y), ps, st)) | ||
@test size(pred) == out_size | ||
|
||
don_ = DeepONet(Chain(Dense(64 => 32), Dense(32 => 32), Dense(32 => 20)), | ||
deeponet = DeepONet(Chain(Dense(64 => 32), Dense(32 => 32), Dense(32 => 20)), | ||
Chain(Dense(1 => 8), Dense(8 => 8), Dense(8 => 16))) | ||
ps, st = Lux.setup(rng_, don_) |> dev | ||
@test_throws ArgumentError don_((u, y), ps, st) | ||
ps, st = Lux.setup(rng, deeponet) |> dev | ||
@test_throws ArgumentError deeponet((u, y), ps, st) | ||
|
||
@testset "higher-dim input #7" begin | ||
u = ones(Float32, 10, 10, 10) |> aType | ||
v = ones(Float32, 1, 10, 10) |> aType | ||
deeponet = DeepONet(; branch=(10, 10, 10), trunk=(1, 10, 10)) | ||
ps, st = Lux.setup(rng, deeponet) |> dev | ||
|
||
y, st_ = deeponet((u, v), ps, st) | ||
@test size(y) == (10, 10) | ||
|
||
@inferred deeponet((u, v), ps, st) | ||
@jet deeponet((u, v), ps, st) | ||
end | ||
end | ||
end |
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