Skip to content

Commit

Permalink
Auto merge of #96 - autumnai:feat/serialization, r=MichaelHirn
Browse files Browse the repository at this point in the history
feat/serialization: add serialization

WIP, the commit for deserialization is still missing because it needs a bit of polish

Will resolve #14, #15
  • Loading branch information
homu committed Apr 19, 2016
2 parents de0eb7c + df7c9d8 commit a6c5aa5
Show file tree
Hide file tree
Showing 16 changed files with 862 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target
Cargo.lock

mynetwork
34 changes: 25 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,30 @@ script:
travis-cargo --only stable doc -- --no-default-features --features $FEATURES
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- libblas-dev
- fglrx
- opencl-headers
- binutils-dev
- nvidia-opencl-dev

- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- libblas-dev
- fglrx
- opencl-headers
- binutils-dev
- nvidia-opencl-dev
- gcc-4.8
- g++-4.8
install:
- git clone https://github.com/kentonv/capnproto.git
- cd capnproto/c++
- git checkout tags/v0.5.3
- ./setup-autotools.sh
- autoreconf -i
- ./configure --disable-shared
- make -j5
- export PATH="$PATH:$(pwd)"
- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)"
- cd ../..
after_success:
- travis-cargo doc-upload
- travis-cargo coveralls --no-sudo --verify
Expand All @@ -46,6 +60,8 @@ notifications:
on_success: never
env:
global:
- CC=gcc-4.8
- CXX=g++-4.8
- secure: QcJ9u0BrVpvjYnerd/3dukvM+GLFQNikIoDHhtKjVenuM2ozZtW6+/RyyXVC1YMh/SghwTnu4Kcnv1sdmwuiC5KWdPoppfalXdxafPkl5PGEfTOexe6L5UAJNW6BdA4lbRKM3xnaUg0Guq6x6tD/zdABIkh8nym/gRLGKT40e9Xitkf6wUQqPBHTGZimip59qg5Fty8lAD48pCBEXynJm+ihA2tz6EDhp0/7wvieHyEl/FqNwvUL5+Z9EeTzEJfKNF8PA5DTHkgeXgeCnWKLm8cCdPEziRZlgdQtvIW27oZBkNTQGHyqI9/tVYhaW4AeKstzE5BoJuyRzmerWYRQCNiz8bgyAjc5HnpWLJPmPSFaGBWTRzwYwUk/iOUP4YEZiN3p0Xj1sKgSB0TA2AjKWND7cufwjrW8NdPdZ3hURVOnM8DHYSQMm2HOfbUNnkw+P5M8n+flT2HKWFdnPhJ3n12rDlLYdHeg9PQ3emJ6kE8Y/jrNT+6yZRrSwLQnsV0uU8Ii44MFQHpdUOGuOIxZFGh9rjKsUwhruUpGtbwI4FWPOqiQJvIaBFY1IUjIVlVCZevvIG3fPXvPksIEKwK93hM/ThDi2PLq2qwBpA87RNfKxDG4S0aR2j19IG+ludbpPcP95mYFVnGCb4rpj44iZoCifC8c9tVqC4L85hEGzik=
matrix:
- FEATURES=travis
Expand Down
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ readme = "README.md"
keywords = ["deep-learning", "neural-networks", "machine-learning", "framework"]
license = "MIT OR Apache-2.0"

build = "build.rs"

[dependencies]
collenchyma = { version = "0.0.8", default-features = false, features = ["native"] } # native feature to read/write data into tensors
collenchyma-blas = { version = "0.2.0", default-features = false, features = ["native"] } # only compiles with native feature
Expand All @@ -22,10 +24,15 @@ log = "0.3.2"
rand = "0.3.0"
num = "0.1"

clippy = { version = "0.0.41", optional = true }
capnp = "0.6.2"

timeit = "0.1.2"

clippy = { version = "0.0.41", optional = true }

[build-dependencies]
capnpc = "0.6.1"

[dev-dependencies]
env_logger = "0.3"

Expand Down
5 changes: 5 additions & 0 deletions build.rs
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();
}
92 changes: 92 additions & 0 deletions capnp/leaf.capnp
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);
}
17 changes: 17 additions & 0 deletions src/capnp_util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! 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);
}

pub trait CapnpRead<'a> {
/// The Reader that was autogenerated by capnp.
type Reader;

/// Read the struct from the Reader.
fn read_capnp(reader: Self::Reader) -> Self;
}

0 comments on commit a6c5aa5

Please sign in to comment.