Open mratsim opened 6 years ago
Would both be feasible? Not having to allocate extra memory is a huge plus. Memory issues are the biggest bottleneck in model design, and tensorflow and others are considering in-place operations. If arraymancer can support memory reuse from the getgo, that would be great.
I'm planning to have the low-level API for layers to only use var params (i.e. convolution, maxpooling, etc) and avoid memory allocation. For activations like relu
or sigmoid
I already provide a mrelu
and msigmoid
in-place version.
Ideally with the future sink/destructors I can provide an optimization when only a single ref is used with a signature like this:
proc sigmoid[TT](v: sink Variable[TT]): Variable[TT] {.inline.}=
msigmoid(v)
result = v
I have started on an object pool due to the cost of allocating memory on Cuda. Custom allocators are planned with Nim destructors, which would ease the implementation of memory regions/object pools to reuse already allocated memory. See stub implementation here.
Removing the easy tag.
It seems like I would need 3 levels of API:
x.function(weight, bias)
. This can be build at the Tensor level, with an overload for Variables.x.function
instead of x.function(weight, bias)
1 is key for efficient RNNs, as we can reuse the buffers across timesteps instead of allocating a new one every time. This is also required for OpenMP or MPI parallelism at a higher level (model parallelism) as allocations within an OpenMP context will crash.
The library is inconsistent in nn_primitives for when to use return values and when to use var parameters that will be updated in place.
var parameter
https://github.com/mratsim/Arraymancer/blob/92aa82e8c7d2a30c4497d5cf367c89f30c648a68/src/nn_primitives/nnp_linear.nim#L20-L28
https://github.com/mratsim/Arraymancer/blob/92aa82e8c7d2a30c4497d5cf367c89f30c648a68/src/nn_primitives/fallback/conv.nim#L19-L20
https://github.com/mratsim/Arraymancer/blob/92aa82e8c7d2a30c4497d5cf367c89f30c648a68/src/nn_primitives/nnp_convolution.nim#L65-L70
return value
https://github.com/mratsim/Arraymancer/blob/92aa82e8c7d2a30c4497d5cf367c89f30c648a68/src/nn_primitives/fallback/conv.nim#L57-L59
https://github.com/mratsim/Arraymancer/blob/92aa82e8c7d2a30c4497d5cf367c89f30c648a68/src/nn_primitives/nnp_convolution.nim#L28-L31
Possibilities
Always use
var
im2col
for example)Always use return values
Return value if single,
var
parameters otherwise?