-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/serialization: add serialization
- Loading branch information
Showing
13 changed files
with
440 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate capnpc; | ||
|
||
fn main() { | ||
::capnpc::compile("capnp", &["capnp/leaf.capnp"]).unwrap(); | ||
} |
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,92 @@ | ||
@0x8316e0f30c445924; | ||
|
||
# The structs here try to mirror all the *Config structs as close as possible. | ||
# Before changing anything take a look at https://capnproto.org/language.html#evolving-your-protocol | ||
|
||
struct Weight { | ||
name @0 :Text; | ||
tensor @1 :Tensor; | ||
} | ||
|
||
struct Tensor { | ||
shape @0 :List(UInt64); | ||
data @1 :List(Float32); | ||
} | ||
|
||
struct Layer { | ||
name @0 :Text; | ||
config @1 :LayerConfig; | ||
weightsData @2 :List(Weight); | ||
} | ||
|
||
struct LayerConfig { | ||
name @0 :Text; | ||
layerType :union { | ||
# Common layers | ||
convolution @1 :ConvolutionConfig; | ||
linear @2 :LinearConfig; | ||
logSoftmax @3 :Void; | ||
pooling @4 :PoolingConfig; | ||
sequential @5 :SequentialConfig; | ||
softmax @6 :Void; | ||
# Activation layers | ||
relu @7 :Void; | ||
sigmoid @8 :Void; | ||
# Loss layers | ||
negativeLogLikelihood @9 :NegativeLogLikelihoodConfig; | ||
# Utility layers | ||
reshape @10 :ReshapeConfig; | ||
} | ||
|
||
outputs @11 :List(Text); | ||
inputs @12 :List(Text); | ||
params @13 :List(WeightConfig); | ||
propagateDown @14 :List(Bool); | ||
} | ||
|
||
# TODO: incomplete since WeightConfig isn't really used internally in Leaf. | ||
struct WeightConfig { | ||
name @0 :Text; | ||
} | ||
|
||
struct ConvolutionConfig { | ||
numOutput @0 :UInt64; | ||
filterShape @1 :List(UInt64); | ||
stride @2 :List(UInt64); | ||
padding @3 :List(UInt64); | ||
} | ||
|
||
struct LinearConfig { | ||
outputSize @0 :UInt64; | ||
} | ||
|
||
struct PoolingConfig { | ||
mode @0 :PoolingMode; | ||
filterShape @1 :List(UInt64); | ||
stride @2 :List(UInt64); | ||
padding @3 :List(UInt64); | ||
} | ||
|
||
enum PoolingMode { | ||
max @0; | ||
average @1; # not implemented yet, but we can't create a single variant enum so this is better than a meaningless "Dummy" value. | ||
} | ||
|
||
struct SequentialConfig { | ||
layers @0 :List(LayerConfig); | ||
inputs @1 :List(ShapedInput); | ||
forceBackward @2 :Bool; | ||
} | ||
|
||
struct ShapedInput { | ||
name @0 :Text; | ||
shape @1 :List(UInt64); | ||
} | ||
|
||
struct NegativeLogLikelihoodConfig { | ||
numClasses @0 :UInt64; | ||
} | ||
|
||
struct ReshapeConfig { | ||
shape @0 :List(UInt64); | ||
} |
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,9 @@ | ||
//! Provides functionality for Cap'n Proto (de)serialization. | ||
|
||
pub trait CapnpWrite<'a> { | ||
/// The Builder that was autogenerated by capnp. | ||
type Builder; | ||
|
||
/// Write the struct into the message that is being built by the Builder. | ||
fn write_capnp(&self, builder: &mut Self::Builder); | ||
} |
Oops, something went wrong.