@@ -9,21 +9,23 @@ using NNlib: DenseConvDims
9
9
@test ∇conv_filter (a, c, cdims) ≈ collect (∇conv_filter (da, dc, cdims))
10
10
11
11
# Test for agreement between CPU NNlib and CuDNN versions, across a variety of kwargs
12
- for num_spatial_dims in (1 , 2 , 3 )
12
+ options = Dict {Any, Any} .((
13
+ (), (:dilation => 2 ), (:flipkernel => true ), (:stride => 2 ),
14
+ (:padding => 1 ),
15
+ ))
16
+ C_in_ = 3
17
+ C_out = 4
18
+ batch_size = 1
19
+
20
+ for groups in (1 , 2 , 4 ), num_spatial_dims in (1 , 2 , 3 )
21
+ # Make `C_in = C_out` when using grouped convolution.
22
+ C_in = groups == 1 ? C_in_ : C_out
13
23
# Initialize data we'll run our tests over
14
- C_in = 3
15
- C_out = 4
16
- batch_size = 1
17
24
x = rand (Float64, fill (8 , num_spatial_dims)... , C_in, batch_size)
18
- w = rand (Float64, fill (2 , num_spatial_dims)... , C_in, C_out)
19
- b = rand (Float64, fill (1 , num_spatial_dims)... , C_in, C_out)
20
- options = (Dict (), Dict (:dilation => 2 ), Dict (:flipkernel => true ), Dict (:stride => 2 ), Dict (:padding => 1 ))
21
-
22
- # @denizyuret: algo option deprecated for nnlib, handling in cudnn
23
- # algos = (1, 0, 1, 1,)
24
- # for (opts, algo) in zip(options, algos)
25
+ w = rand (Float64, fill (2 , num_spatial_dims)... , C_in ÷ groups, C_out)
25
26
26
- for opts in options
27
+ for opts in options
28
+ opts[:groups ] = groups
27
29
cdims = DenseConvDims (x, w; opts... )
28
30
y = NNlib. conv (x, w, cdims)
29
31
@@ -36,19 +38,11 @@ using NNlib: DenseConvDims
36
38
gputest ((x, w) -> NNlib. conv (x, w, cdims; alpha= 2.0 ), x, w, checkgrad= false ) # TODO
37
39
gputest ((y, w) -> NNlib.∇conv_data (y, w, cdims; alpha= 2.0 ), y, w, checkgrad= false ) # TODO
38
40
gputest ((x, y) -> NNlib.∇conv_filter (x, y, cdims; alpha= 2.0 ), x, y, checkgrad= false ) # TODO
39
-
41
+
40
42
gputest ((y, x, w) -> NNlib. conv! (copy (y), x, w, cdims; beta= 2.0 ), y, x, w, checkgrad= false ) # TODO
41
43
# @test_broken gputest((x, y, w) -> NNlib.∇conv_data!(copy(x), y, w, cdims; beta=2.0), x, y, w, checkgrad=false) #TODO
42
44
gputest ((w, x, y) -> NNlib.∇conv_filter! (copy (w), x, y, cdims; beta= 2.0 ), w, x, y, checkgrad= false ) # TODO
43
45
end
44
-
45
- # CPU implementation of ∇conv_bias!
46
- db = zeros (Float64, 1 , 1 , 3 , 1 )
47
- dy = randn (Float64, 8 , 8 , 3 , 1 )
48
- function NNlibCUDA. ∇conv_bias! (db, dy)
49
- db .= sum (dy, dims= 1 : (ndims (dy)- 2 ))
50
- return db
51
- end
52
- gputest (NNlibCUDA.∇conv_bias!, db, dy, checkgrad= false )
53
46
end
47
+
54
48
end
0 commit comments