Adding nn builder structs, dtype generics, and remove device defaults. #433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #419
In order to support multiple dtypes, the nn api needs to have a generic over dtype, similar to tensors. Additionally, the device generic being defaulted to Cpu was causing issues with other APIs, so this PR removes it.
The above two changes meant that any specification of a nn module required also specifying the dtype & device, which could quickly grow out of hand.
This PR thus introduces a number of "builder" unit structs that implement the
BuildOnDevice
trait, so you don't have to specify either dtype or device.Here is Conv2D as an example:
Here we see that we can get default generics for free on builder structs, and utilize BuildOnDevice to build the actual struct.
Considerations for future
nn::conv::builder::Conv2D
andnn::conv::Conv2D
, which have the same name. this could cause confusionmodules
andbuilders
. The prior should be used when building a new network layer, and the second should be used when declaring a network structure