Commit graph

328 commits

Author SHA1 Message Date
James Reed
8de1db9eb6 Implement recurrent attention in C2
Summary: Super rough implementation of recurrent attention. Planning to factor out the common code between the two functions as well as train and eval. I want to get this out and get eyes on it sooner rather than later

Differential Revision: D4647837

fbshipit-source-id: 54bc4e8ed0df6f04c86c425926decbe89f73b068
2017-03-08 11:21:28 -08:00
Kittipat Virochsiri
f0d78753ae Make ModelExporter.load_from_db() load to specific workspace
Summary: In case of distributed task, load_from_db() loads to wrong workspace (when used inside a Python op). Passing which workspace to use explicitly so that it loads to the one Python op is being run.

Reviewed By: kennyhorror

Differential Revision: D4653692

fbshipit-source-id: 94585c012b05ee38b9ce5e8ef0efdd50aa41dd2b
2017-03-08 09:31:42 -08:00
Jiyan Yang
e75221e316 Add eval net to two tower workflow
Summary: The evaluation part of the two tower workflow is missing. This diff is to complete it. Part of the newly added functions can be used for other workflows, eg, feed. As the eval workflow in different workflows will be overlapped, a generic eval workflow will be added in a separate diff.

Reviewed By: kennyhorror

Differential Revision: D4646880

fbshipit-source-id: 4d6eb35df10f6f613533d442f2a04dc0332386f8
2017-03-07 21:03:00 -08:00
James Cross
8de2027d9b Add gradient operator for SumElements
Summary: Add gradient support for Caffe2 operator SumElements (for use in Translation RNN training pipeline).

Differential Revision: D4669036

fbshipit-source-id: 502760a2a624b20b3241e83a2f208f450b6ff36f
2017-03-07 20:03:07 -08:00
Huazhong Ning
83437853ad refactor and modulize optimizers
Summary:
The current optimizer code in c2/python has the following issues:
(1) the optimizers in sgd.py cannot config per param-blob optimizer;
(2) sgd.py is a bad file name. optimizer.py is a better name;
(3) layer_model_helper.py has another set of optimizer code (which supports per param-blob optimizer)

This diff did the following
(1) create optimizer objects so that we can config per param-blob optimizer and that are also compatible to the existing optimizer code
(2) the new optimizer code are much more modulized
(3) move the optimizer code to file with better name (optimizer.py)
(4) replace the optimizer imports in the existing code

will do in next diffs
(1) optimizers with structured parameters for dper2
(2) get rid of the optimizer code in layer_model_helper.py

Reviewed By: salexspb

Differential Revision: D4609013

fbshipit-source-id: 2e2d6dfa8685d10498f89069157453d9feca3f27
2017-03-07 18:46:47 -08:00
Xiaolong Wang
ed693b1c6a add EnsureDense Op in MTML MLP
Summary:
1. Allow EnsureDense Op to do both in-place pass or copy
2. In MTML, add EnsureDense Op before gather
3. Change the unittest values (adding another operator changes the random seed,
  which causes the model initialization also changes)

Reviewed By: xianjiec

Differential Revision: D4625219

fbshipit-source-id: b3c748c3651d1dedd75420912a9698b7e46187c5
2017-03-07 14:03:49 -08:00
Andrey Malevich
b599910f3a Use new metric intefaces in trainer workflows.
Summary: This diff is migrating existing DPER workflows to use new metric abstractions in training.

Reviewed By: xianjiec

Differential Revision: D4656576

fbshipit-source-id: 1b3b16b390fc0757480e41df1c4214c11cd76e8a
2017-03-07 12:46:52 -08:00
Aapo Kyrola
d8588d8007 CUDA version of elementwise power + rename to Pow + gradient
Summary: Renamed ElementwisePower to Pow for better discoverability. Added CUDA version and Gradient + tests.

Reviewed By: kennyhorror

Differential Revision: D4665550

fbshipit-source-id: dd33d8ad3917d71504e363ab397af50d38a63b1f
2017-03-07 10:20:40 -08:00
Aapo Kyrola
695ea6c7a1 SumElementsOp
Summary: Add a simple op to sum the elements, with optional averaging. This is basically copy from AverageLossOp that we should alias to this. And maybe develop this towards a generic norm op.

Reviewed By: jhcross

Differential Revision: D4664591

fbshipit-source-id: 0e0c0efe9e415e2ad2feecfa42b03db2c83bee70
2017-03-07 05:23:53 -08:00
Aapo Kyrola
8fab453863 Sqr op and gradient
Summary: Due to popular demand, added an op to compute element-wise square + gradient for it (just for the fun of it).

Reviewed By: Yangqing

Differential Revision: D4664797

fbshipit-source-id: 0a29c7c249fdc72f51412bebd6ae352a7801cf05
2017-03-07 03:03:07 -08:00
Dmytro Dzhulgakov
560572910c Add task outputs and stop signals to net_printer
Summary: Useful for debugging of multi_reader.

Reviewed By: kennyhorror

Differential Revision: D4664954

fbshipit-source-id: ba7a307db444b61a7e520992ee44c35237906068
2017-03-07 01:21:40 -08:00
Kairan Sun
9f588aa8a2 Add Inference for Flatten
Summary: Implementing shape inference for Flatten operator and adding unit tests.

Differential Revision: D4664073

fbshipit-source-id: c54a269fc7633908fe4197682d27076ef97d9c22
2017-03-07 01:21:40 -08:00
Aapo Kyrola
2333ccadfb MaxOp for CUDA
Summary: Simple elementwise Max implementation for CUDA. Given N inputs, it will do N-1 pairwise maxes. I am not sure if it would be much better to iterate through all the inputs in the kernel, since this has better locality. We can also optimize later.

Reviewed By: Yangqing

Differential Revision: D4659953

fbshipit-source-id: 3a23b7fb3dbdf1d43bf3134ece03af4a791844dd
2017-03-06 16:46:53 -08:00
Andrey Malevich
3e54601bab New approach to metrics.
Summary:
This diff is modifying the way we're specifying metrics from doing reporter, that should know all the blobs which is should access in advance, to reporter that is connected through schema.

This diff is also reporting any arbitrary number of learning curves to Flow and provides really flexible way to specify all the metrics we care about.

TODO: Modify model helper to allow providing intermediate results for reporting
TODO: Add evaluation net (instead of prediction net).
TODO: Move all other places in DPER 2.0 to use that abstractions instead.
TODO: Get rid of LogScoreEstimator in favor of metric that is going to be really suiting our needs.

Reviewed By: azzolini, dzhulgakov, kittipatv

Differential Revision: D4577548

fbshipit-source-id: 3515bd41e0f92263ff90ce2f7207abf65d01b1f7
2017-03-06 14:48:16 -08:00
Huazhong Ning
f747bbec2e move the dper 1.0 utils to c2 or fb utils
Summary: so that the utils can be used by a wider range of audience.

Reviewed By: xianjiec

Differential Revision: D4637462

fbshipit-source-id: f0695f430902aef26360efa511069b3755eaf52a
2017-03-06 14:31:45 -08:00
Chonglin Sun
7472631e7f fix bug in Mean pooling
Summary: simple fix

Reviewed By: xianjiec

Differential Revision: D4655469

fbshipit-source-id: 6dbcfcd2f3f7f7bd74aca88af4f60c6ddffb9138
2017-03-06 11:31:10 -08:00
Pooya Davoodi
c61a7ca777 Make counts datatype int. Used as index.
Summary:
To avoid Numpy warning: using a non-integer number instead of an integer will result in an error in the future
Closes https://github.com/caffe2/caffe2/pull/64

Differential Revision: D4658348

Pulled By: Yangqing

fbshipit-source-id: 3a1b33cbb27849bc167b08147d078e8d487567f4
2017-03-06 10:46:36 -08:00
Wael Abdelghani
9ef35f4a0b Add validation checks to load op
Summary: Added validation for load op when doing load_all by refactoring validation logic for loading specific blobs.

Reviewed By: kennyhorror

Differential Revision: D4641986

fbshipit-source-id: e0075a12188ca09d7628add72c143b40d5d9f382
2017-03-06 09:46:35 -08:00
Pooya Davoodi
aef75ca5dd Strip prefix of strip_prefix in blob names before save and load.
Summary:
- Replaces strip_regex implementation in SaveOp. It deletes the prefix of blob names upto a given substring.
- Adds the same functionality to LoadOp. Needed for loading checkpoints that are stored using the strip_prefix feature.
Closes https://github.com/caffe2/caffe2/pull/129

Differential Revision: D4512234

Pulled By: Yangqing

fbshipit-source-id: d926c1c5adcc7a711365cede11f21421bb7d4138
2017-03-04 15:46:47 -08:00
Aapo Kyrola
8caa7cec8d CUDA version of Log
Summary: As in the title. Simple registration issue.

Reviewed By: Yangqing, jhcross

Differential Revision: D4655691

fbshipit-source-id: 661e4d5f1226ec05e099c84f4454aa07c6be4449
2017-03-04 00:32:03 -08:00
Artem Volkhin
8c4310ac16 minor fix for _add_net_to_dict
Summary: fix a check if the net is net_dict

Reviewed By: kennyhorror

Differential Revision: D4647493

fbshipit-source-id: e0a62fc5847c99c85857c5635b4e39d59c66d5ce
2017-03-02 23:31:27 -08:00
Huazhong Ning
6c9105447c support fill bool tensors in GivenTensorFill
Summary:
the existing code uses vector<T> to store the given tensor and then copy to output.
If T=bool, vector<bool> stores the data as bits and then copy does not work.
we use TensorCPU to store it instead.
Also add unittest.

Reviewed By: kennyhorror

Differential Revision: D4622325

fbshipit-source-id: 95c27b5d1cfbc836d2419d01cacde5a3172f4d7e
2017-03-02 20:18:59 -08:00
Andrew Dye
b6fbc708f5 Verify InferShapesAndTypes() in operator unittests
Summary:
Verify shape and type inference in op unittests via assertReferenceChecks(). For now catch exceptions from InferShapeAndTypes() and log a warning.

TBD: Determine if there existing inference/output mismatches, and if so, change test asserts to warnings until they are resolved.

Differential Revision: D4639343

fbshipit-source-id: 605e72f53198e1a100fe7ba18b72c34c9ddbb727
2017-03-02 20:18:59 -08:00
Pooya Davoodi
e9c0671132 Convnet benchmark cudnn_ws
Summary:
- Do not set default for cudnn_ws. Will use the default set by cuDNN ops.
- Do not use cudnn_ws for MLP.
- Do not run the benchmark if the required args are not set. Previously tried to run and errors out.
Closes https://github.com/caffe2/caffe2/pull/177

Differential Revision: D4633143

Pulled By: Yangqing

fbshipit-source-id: e89a7d01984e599d92a330d0ee4ba106feba65b8
2017-03-02 15:32:37 -08:00
Simon Layton
73db5f902e Fbsync cudnn rnn fix
Summary:
Update cuDNN RNN interface (mostly fixing ordering of arguments). Set seed so that test can pass consistently
Closes https://github.com/caffe2/caffe2/pull/62

Reviewed By: Yangqing

Differential Revision: D4348966

fbshipit-source-id: f9b56be37739e5bffabec130e3407492b2aef656
2017-03-02 05:31:21 -08:00
Aapo Kyrola
ec56737190 fix shape inference for spatial softmax with loss
Summary: The shape inferenec did not check for spatial mode.

Reviewed By: andrewwdye

Differential Revision: D4638218

fbshipit-source-id: f15419738587013dea39e04a3da086890938c4e2
2017-03-01 19:32:32 -08:00
Andrey Malevich
6cb63df704 Default LocalSession to current workspace.
Summary:
At the moment LocalSession creates a new workspace if none if provided. As a
result anything that have been executed in local session is not going to be
avaiable to the external caller, i.e. everything that is using SingleRunner can
only observe side-effects and not really access intermediate blobs.

This diff is modifying LocalSession to run in current workspace instead (unless
it gots some really weird effects because we rely on privateness of the
workspace it should work).

Differential Revision: D4634743

fbshipit-source-id: 975bed154c7ca215dc3fc0d60f05a7c092711482
2017-03-01 16:03:18 -08:00
Aapo Kyrola
2cddbc719c Euthanize a process with timeout
Summary: vigneshr has been experiencing randomly that the process does not exit in the end. We don't know what causes this, so this will help with two ways: (1) by putting timeout_guard.EuthanizeIfNecessary(600) in the end of the operator, you ensure that the process is killed in 10 minutes, allowing for retry; (2) this killing will cause python stack traces to be dumped, helping debug the real issue.

Differential Revision: D4635781

fbshipit-source-id: b558418c80671c00effdd514e4ddc01e935c95df
2017-03-01 11:38:11 -08:00
Qichao Que
2f68632a32 Add SparseNN workflow for feed.
Summary: Add SparseNN workflow for feed. I haven't fully thought about the change needed for ads, as I added a property called 'preproc_output_schema' for LayerModelHelper.

Reviewed By: xianjiec

Differential Revision: D4585796

fbshipit-source-id: 060d08f4beb928e7e7863f2e563f612c358951fb
2017-03-01 11:02:38 -08:00
Aapo Kyrola
aa3156c235 Remove use of logging module and np.random.randint() due to deadlocks with forks
Summary: See http://bugs.python.org/issue6721. Since everstore loaders use ProcessPoolExecutor, which is based on forks, and there was perhaps update of the numpy library or some unralted lirbary, we started getting subprocesses stuck at np.random.randint().   Also changed logging to prints, since logging is known to have issues with multiprocessing.  See https://www.prod.facebook.com/groups/fbpython/permalink/1438647216176641/

Differential Revision: D4633725

fbshipit-source-id: ae948a1827c71a3a2119d6a3248706728984df31
2017-03-01 03:32:56 -08:00
Aapo Kyrola
02937903cc add inference for gradient ops + a couple of missing shape inference functions + fix to scalars
Summary:
A bit too much stuff in one diff, so sorry:

1. Add inference for gradient types by using the fact that x_grad is gradient of x and must be of same shape. This is kind of awkward to use string matching, but in addition I rely on the operator being actually a gradient op.
2. dzhulgakov was write, scalar shape is () and not (1). Sorry, my claim easlier was #fakenews.
3. Added inference functions for MakeTwoClass, MomentumSGDUpdate and Cross entropy ops.

Reviewed By: dzhulgakov

Differential Revision: D4569758

fbshipit-source-id: 0db13f33819777fdddefe21d4b1ebf906fcaf98c
2017-02-28 23:33:32 -08:00
Aapo Kyrola
f84e5360cc LSTM benchmark (Caffe2 RNN based)
Summary: Just generate some random data and put it through LSTM (Cafef2 RNN based) using its own output as gradient value for benchmark purposes. With default parameters it fits my dev GPU memory. On default parameters provided in this diff I have got 300k entries per second processed. These entries are split into blocks of seq_length * block_size. Each entry is of size hidden_dim, LSTM takes in hidden_dim sized input and produces output of the same size.

Reviewed By: salexspb

Differential Revision: D4605815

fbshipit-source-id: dd529302a0a93e8711784c67e4c777c8d6a8cdf4
2017-02-28 23:17:26 -08:00
Jerry Pan
8a0ebed4c9 Caffe2: Tile operator
Summary: Caffe2: Tile operator

Differential Revision: D4630698

fbshipit-source-id: 1aa5c3c9d7fcfc17f78c80fd4b752595280266a0
2017-02-28 23:17:26 -08:00
Yangqing Jia
bdd542d087 backup functions for non-cuda cases
Summary: This fixes the error introduced in cudnn v6 diff.

Reviewed By: ajtulloch

Differential Revision: D4633113

fbshipit-source-id: 454cd4b3e52b8de01c1914e66d25310d7ecb13aa
2017-02-28 22:07:54 -08:00
Luke Yeager
69fa85be26 Fix some typos
Summary:
Found while reading through d522693cc8
Closes https://github.com/caffe2/caffe2/pull/176

Differential Revision: D4630275

Pulled By: Yangqing

fbshipit-source-id: 0a8e85d317d427a39467ebcb5e9a70594075bae2
2017-02-28 18:36:12 -08:00
Simon Layton
fbf47a8825 Cudnn v6
Summary:
Add cudnn v6 support, including testing support for dilated convolution.
Add a check to ensure that the versions of cuDNN used to compile Caffe2 and run it are compatible
Closes https://github.com/caffe2/caffe2/pull/85

Reviewed By: bwasti

Differential Revision: D4387690

Pulled By: Yangqing

fbshipit-source-id: 312960134398dd4afe6ee0c01cdc160046c904e8
2017-02-28 17:46:33 -08:00
Zachary Mirman
1c92e85dae Added editDistance helper to caffe2 operators
Summary: Added editDistance helper to caffe2 operators

Differential Revision: D4622152

fbshipit-source-id: 4d6246b8226c1283d5883edfaa27e8f7748fdc4c
2017-02-28 13:31:56 -08:00
Artem Volkhin
000db87bc7 Half-floats support for the rest of segment ops
Summary:
previously fp16 type was supported in SparseLengthsSum operator, now it
works in all other segment operator as well.

Reviewed By: dzhulgakov

Differential Revision: D4624312

fbshipit-source-id: c9d72110e3762167270bb088405eaf9c56e88493
2017-02-28 11:19:15 -08:00
Andrey Malevich
a3726759c6 Add a way do describe layers in a more AdHoc manner.
Summary:
This diff is trying to address one of the concerns that Xianjie have had - requirements create a layer for all operators and attach pass shapes and other info around.

The basic idea of the diff:
1. Try to create a layer with a given name, but if it's not available try to fallback on operator with that name (that is expected to have no parameters).
2. For all operators that we're adding through this functional style of creation - try to use C2 Shape/Type inference logic to get output type. If we fail to get - it just return untyped record and expect user to annotate it when it's really needed.

Reviewed By: xianjiec

Differential Revision: D4408771

fbshipit-source-id: aced7487571940d726424269970df0eb62670c39
2017-02-27 23:30:39 -08:00
Aaron Markham
851cb7059d changed StringfyProto to StringifyProto
Summary: Closes https://github.com/caffe2/caffe2/pull/155

Reviewed By: dzhulgakov

Differential Revision: D4621607

Pulled By: Yangqing

fbshipit-source-id: ec7f45132260fbb6d36ef61ffbf5bf6466f237eb
2017-02-27 23:05:04 -08:00
Pooya Davoodi
d85ca8c6df Do not initialize BN params if init_params is false.
Summary:
If init_params is False, the parameters should not be initialized.
This is particularly important when testing a model that provides values for these BN parameters.
Closes https://github.com/caffe2/caffe2/pull/174

Differential Revision: D4621791

Pulled By: Yangqing

fbshipit-source-id: 518443925990a12c1d5729b0971ebe19ba5d8998
2017-02-27 20:19:03 -08:00
Aapo Kyrola
7b0126381c Share queue + reduce logging
Summary: It is better for the workers to share the python-side queue, since I saw a case where workers assigned for one GPU was lagging behind others. Also, reduced logging as requested by rpenggithub.

Differential Revision: D4620487

fbshipit-source-id: 73353f9570b07788c8cd71c9fec9308cd93a44dd
2017-02-27 19:38:45 -08:00
Kun Huang
07623e24c9 Implement shape inference function for Im2Colop
Summary: Inference function for the Im2ColOp: caffe2/caffe2/operators/im2col_op.cc.

Differential Revision: D4608663

fbshipit-source-id: d26ffb403c2acb7a5ead5f58f044ee3340c8311a
2017-02-27 10:46:54 -08:00
Aapo Kyrola
449f8997ab close blobs queues when stopping + test
Summary:
Mysterious deadlocks after epoch has finished have occured randomly but quite frequently recently for myself, vigneshr and others. Looking at a stack trace of vigneshr's job (P57129798), I noticed a couple of threads were calling BlobsQueue.blockingWrite (or something like that). That call stucks when the caffe2/c++ side queue is at capacity (we use capacity of 4 with data workers). So in cases when this call was just being made while the script was to be terminated, the thread did not close and the whole process did not close either (not completely sure why that is since thread is a daemon thread, but this might be a flow-related issue since we run inside a flow container).

This is quite easy to fix: just call CloseBlobsQueue() when terminating the process. I modified coordinator.stop() and wait_for_finish() to return a status code based on whether threads that were joined actually closed within the 1.0sec timeout. This allowed creating an unit test to test for this issue. Before my change, the unit test failed.

Reviewed By: pietern

Differential Revision: D4619638

fbshipit-source-id: d96314ca783977517274fc7aadf8db4ee5636bdf
2017-02-27 10:07:57 -08:00
Kevin Matzen
04d02632e9 instance norm test fix
Summary:
Reduce test input size to instance norm gradient check.  Larger size is currently timing out on stress tests.
e.g. failed: Timeout: Ran out of time before finding a satisfying example for test_instance_norm_gradients. Only found 2 examples in 125.39s.

Reviewed By: Yangqing

Differential Revision: D4608828

fbshipit-source-id: ce17a3ad28752d808efcbf79f1ea4238e63fb005
2017-02-25 14:31:42 -08:00
Peng Yang
8ab13eea6f delete redundant comment lines.
Summary: delete redundant comment lines.

Differential Revision: D4600596

fbshipit-source-id: 4bb619f9ff99d6f799e87970b6b6d5ea7de02c98
2017-02-24 11:04:36 -08:00
Xianjie Chen
b257fd8e83 Other places that may need NameScope
Summary:
For code in layer model helper, layers. It's intentionally to not have NameScope by default.

This looks another place that may need default NameScope.
https://fburl.com/wdwtxp0m

Reviewed By: kennyhorror

Differential Revision: D4606971

fbshipit-source-id: b560bf59d3242e3f9443cd5aeda5c7e2e4e89079
2017-02-23 21:16:35 -08:00
Aapo Kyrola
9eeeb8407f use CUDA version of AccuracyOp with top_k=1
Summary: D4348953 added support for accuracy for top_k>1, which is only supported on CPU, requiring data to be copied to CUDA. But that diff did not take into account that we have top_k=1 version of AccuracyOp for CUDA. This diff ensures we use the CUDA version for top_k=1.

Differential Revision: D4607767

fbshipit-source-id: 8becda23890343043eb79ad04e4c6196e9010f0c
2017-02-23 19:02:53 -08:00
Min Li
182c168285 Add group collector limit and add option for enable sum loss
Summary: as title. Add num of examples limit for group collect. Add option for enabling sum loss in BatchLRLoss

Reviewed By: xianjiec

Differential Revision: D4602311

fbshipit-source-id: 5b2a244f1f0e9f1ab0f4590e94828fd18d018d8d
2017-02-23 15:03:22 -08:00
Deepak Gopinath
cd4ea42048 Allowing creation of random odd length arrays in RandGaussian
Summary: curandGenerateNormal can only generate arrays of multiple of 2 lengths. MSRAFill and GaussianFill operators use RandGaussian utility method which in turn uses curandGenerateNormal. This is a test which runs the operators on both devices to generate odd sized random arrays.

Differential Revision: D4602819

fbshipit-source-id: e65f5c731e925886cfa14afff482f7053bd020a0
2017-02-23 15:03:22 -08:00