Commit Graph

139 Commits

Author SHA1 Message Date
gchanan
affe742d31
Add scalar module tests for test_nn. (#5116)
* Add scalar module tests for test_nn.

* Properly return from glu.

* Guard scalar test with skipIf.
2018-02-08 13:53:24 -05:00
gchanan
1de4501078
Add scalar module tests for common_nn. (#5095)
* Add scalar module tests for common_nn.

* Properly skip cuda Hardshrink tests.

* Fix flake8.
2018-02-07 14:09:24 -05:00
gchanan
7af433deeb
Add scalar criterion tests (#5087)
* Add criterion scalar tests.

This exposed an issue in MarginRankingLoss with scalars, but the cleanest way to fix is to wait
until forward runs on Variables (so we don't have to wait for the backward to check if something
is a scalar).

* Fix flake8.

* Add error message for margin_ranking_loss with scalars.
2018-02-06 18:40:37 -05:00
gchanan
67ff50c30d
Run test_nn criterion tests over Variables, add a scalar test (#5058)
* test_nn working.

* Fix some incorrect scalar assumptions.

* Don't use Variables when we don't have to.

* Use Variable Mixin.

* Fix NLLLoss reference function when WITH_SCALARS not enabled.

* Allow device to be optional in cuda().

* Fix multilabelmarginloss_reference.
2018-02-06 11:11:18 -05:00
li-roy
28f056fed2 add reduce=True argument to MultiLabelMarginLoss (#4924)
* add reduce=True argument to MultiLabelMarginLoss

* Fix lint

* Addressed comments

* Remove unneeded syncthreads calls
2018-02-05 12:28:51 -05:00
Edward Z. Yang
e22095b09d
Add some more builder scripts from ossci-job-dsl (#4945)
* Add some more builder scripts from ossci-job-dsl

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

* Relax precision requirement on test_Upsample_trilinear_scale_3d_cuda

Partially addresses #5006.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2018-02-02 11:14:56 -05:00
Edward Z. Yang
c3b7baecea Fix #4422, use grad for cudnn_batch_norm derivative / don't use toTensor()
This commit fixes double-backwards on batch norm.  There were two
bugs:

- Returned buffers from batchnorm backwards were being marked as differentiable
  when they shouldn't be.  The fix for this is "easy": use 'grad' instead of
  'grads[0]' in cudnn_batch_norm's backward definition.  (More on this below.)

- I was using toTensor on a Scalar, which gives me a Tensor of the wrong
  type when I'm in CUDA world.  Using the Scalar add() overload directly
  solves the problem.

The differentiability of returned buffers was annoyingly subtle and I nearly
went off and implemented a big pile of infrastructure to "tell" the codegen how
to distinguish between differentiable and non-differentiable outputs before
realizing that there must be a way we do this legitimately, because it works for
THNN.  I documented this in derivatives.yaml, and also added tests for the
problem in load_derivatives.py to catch the various ways you could "get it
wrong".  Hope this helps someone else.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2018-01-16 12:24:55 -05:00
David Pollack
05908e8243 current code works with dim = 3, so I added it to dim checks 2018-01-13 12:58:08 +01:00
Edward Z. Yang
bc7a41af7d
Ensure convolution weights are contiguous, fixes #4500 (#4543)
* Ensure convolution weights are contiguous, fixes #4500

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2018-01-10 17:33:31 -05:00
Edward Z. Yang
0f8ece5657 Actually test CUDA double-backwards codepath.
Previously, we only tested CPU double-backwards, which is bad!
This would have caught #4422 (still not fixed, so those tests
are manually disabled) and also uncovered #4500 (not yet diagnosed.)

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2018-01-06 10:58:05 -05:00
Richard Zou
35c4d73bdb Deprecate nn.NLLLoss2d (#4238)
* Deprecate nn.NLLLoss2d

* Fix legacy tests

* Fix tests

* Remove NLLLoss2d from docs, add deprecation warning instead of error

* fix lint

* Add more to docs
2018-01-04 12:38:04 -05:00
Richard Zou
ccf4dc1525 Add reduce arg to BCELoss (#4231)
* Add reduce arg to BCELoss

* Fix test precision

* reduce keyword for BCELoss in derivatives.yaml
2017-12-18 12:28:53 -05:00
Soumith Chintala
54d689253e
Revert "Add reduce arg to BCELoss" (#4221)
* Revert "Add reduce arg to BCELoss (#3532)"

This reverts commit 847c56aeb5.
2017-12-18 03:13:09 -05:00
Richard Zou
847c56aeb5 Add reduce arg to BCELoss (#3532)
* Add reduce arg to BCELoss

* Fix test precision
2017-12-18 02:39:49 -05:00
Richard Zou
30e6898808 Implement NLLLossNd (#4035)
* Implement NLLLossNd

* Fix tests and typos

* Fix tests
2017-12-18 02:16:16 -05:00
Sam Gross
93e489d168 Fix _analytical_jacobian to not require in-place grad accumulation 2017-11-27 20:03:44 +01:00
Richard Zou
77ddd5130b Add reduce keyword for KLDivLoss (#3330) 2017-11-07 08:57:11 -05:00
Richard Zou
bf4c269bee Implement reduce keyword for SmoothL1Loss (#3382)
* Implement reduce keyword for SmoothL1Loss
2017-11-01 06:29:34 -04:00
Richard Zou
3853d5da97 Add reduce keyword to NLLLoss and NLLLoss2d (#3080)
* API changes

* Implement reduce for THNN ClassNLLCriterion

* Implement reduce keyword for THCUNN ClassNLLCriterion

* Implement reduce for THNN SpatialClassNLLCriterion

* Implement reduce for THCUNN SpatialClassNLLCriterion

* Make legacy NLLLoss work

* Docs for NLLLoss reduce

* reduce keyword for double backwards NLLLoss

* reduce=False tests

* Addressed comments

* Fix trailing whitespace

* Fix test failures in legacy nn

* Rebase: add reduce keyword to aten declarations of NLLLoss

* Add reference functions for all NLLLoss and NLLLoss2d test cases

* Replaced slow get/set fns. Don't use int64_t in kernels.

* Use TH_INDEX_BASE in NLLLoss for consistency

* Fix legacy ClassNLLCriterion tests
2017-10-26 13:54:19 -04:00
Sam Gross
f1f64c8d07 Generate autograd functions for NN / more refactors (#3136)
Generate autograd functions for NN and implement more derivatives in derivatives.yaml

A big refactor of gen_variable_type.py
2017-10-19 15:03:26 -04:00
Adam Paszke
98e67448fa Large Softmax and LogSoftmax refactor
- Cleaned up THNN and THCUNN code and kernels
- Improved THCUNN kernel performance 5x, making it match cuDNN performance
- Added support for computing softmax over arbitrary dims
  NOTE: The default dim for 3D inputs is now 1 (used to be 0)
- Both functions now accept inputs with arbitrarily many dimensions
- Autograd functions no longer save the input (it's unnecessary)
- Added cuDNN bindings for softmax, but they are unused as THCUNN
  matches or even exceeds cuDNN performance
2017-10-19 19:51:10 +02:00
SsnL
b2f5ccf366 lint 2017-10-06 10:39:33 -04:00
SsnL
ecdb86e733 Update all existing nn tests to new args format; Move all randomness inside tests 2017-10-06 10:39:33 -04:00
SsnL
c76e2900a8 Change TestCase args to accept value, size or fn for constructor_args, input and target 2017-10-06 10:39:33 -04:00
gchanan
9c948c22b5 Fix check_no_size_average tests. (#2532)
* Fix check_no_size_average tests.

* size_average / sizeAverage for non-legacy vs legacy.

* Fix lint.
2017-08-25 12:27:26 -04:00
Gregory Chanan
e37847af92 Test CrossEntropyLoss double backwards. 2017-08-22 11:12:03 -04:00
Gregory Chanan
0390e80a7e Support MarginRankingLoss double backwards. 2017-08-22 11:12:03 -04:00
Gregory Chanan
e27127391d Support double backwards for SoftMarginLoss. 2017-08-22 11:12:03 -04:00
Gregory Chanan
fb7e9583bd Generate no_size_average criterion tests by specifying check_no_size_average=True 2017-08-22 11:12:03 -04:00
Gregory Chanan
7aeb837895 Implement HingeEmbeddingLoss double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
1efe38768d Implement KLDivLoss double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
5106ce67bb Implment SmoothL1Loss double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
19d4c37ced Implement MSELoss double backward. 2017-08-14 16:19:10 -04:00
Gregory Chanan
9a243abe5c Implement Softmin double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
988b0d58e6 Implement LogSigmoid double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
0c3a01fe44 Implement SoftShrink double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
8d38c0ee52 Implement Softplus double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
ea9a7823b4 Implement Hardshrink double backwards. 2017-08-14 16:19:10 -04:00
Gregory Chanan
a6cccc8701 Implement RReLU double backwards. 2017-08-14 16:19:10 -04:00
gchanan
f484a5fee8 Implement LogSoftmax double backwards (#2270) 2017-08-02 07:17:09 +05:30
Gregory Chanan
61c873cc7d Implement SoftMax and NLLLoss double backwards. 2017-08-01 14:29:33 +05:30
Gregory Chanan
c12b494329 Implement double backwards for ELU. 2017-07-25 07:37:25 +05:30
Gregory Chanan
506d52dc33 Add check_gradgrad=False for new NLLLoss2d test. 2017-07-25 07:37:25 +05:30
Gregory Chanan
7687c2677a Fix double backwards advanced indexing derivative wrt grad_output.
Also small legacy nn test issue and unrelated syntax issue.
2017-07-25 07:37:25 +05:30
Gregory Chanan
97d21e243b Implement L1Cost double backwards. 2017-07-25 07:37:25 +05:30
Gregory Chanan
0bda56956e Implement double backwards for auto-generated HardTanh. 2017-07-25 07:37:25 +05:30
Gregory Chanan
9608e37969 Implement double backwards for PReLU. 2017-07-25 07:37:25 +05:30
Gregory Chanan
ec7c510557 Implement Softsign double backwards. 2017-07-25 07:37:25 +05:30
Gregory Chanan
fb2284f3a0 Add gradgrad checks for NN module and criterion tests. 2017-07-25 07:37:25 +05:30
Aron Barreira Bordin
11f3ccf98f Add missing Modules to nn.functional (#1801)
* add dropout2d and dropout3d to functional

added some loss functions to functional

added tests

using dropout from backend

added docs

fixes

* edited loss modules to call functional
2017-07-19 15:55:21 -04:00
Fisher Yu
d6bc2642e7 Add ignore_index to NLLLoss2d 2017-07-13 23:22:48 -04:00
Gregory Chanan
5b81746767 Simplify python warning settings and cleanup tests. 2017-06-11 05:37:59 -04:00
Gregory Chanan
1ef4cc1591 Incorporate review comments:
1) Line up trailing dimensions in broadcast docs.
2) remove unnecessary expand_as in common_nn test.
3) use view in tensor_str instead of resize_.
4) newExpand remove raiseErrors change.
5) clarify expandedSizes/expandedStrides parameters in inferExpandGeometry.
6) simplify inferSize2/inferSizeN implementations.
7) use new-style classes for warning.
2017-06-11 05:37:59 -04:00
Gregory Chanan
be65f46c76 Add optional warning for backwards incompatible keepdim. Setting torch.utils.backcompat.keepdim.warning.enabled=True will cause Python warnings in the case where the default value of keepdim is used for 1-d reductions.
Also specify keepdim via kwargs in library so these warnings have less
noise.
2017-06-11 05:37:59 -04:00
Gregory Chanan
ae2b2cbbec Make keepdim work with autograd. 2017-05-09 14:15:59 -07:00
Adam Paszke
702a2e3bc5 Make Variables not subclass Function anymore
Because of this Variables can no longer appear in the graph.
Every usage of a leaf Variable will leave an AccumulateGrad
function that has no outputs, but modifies var.grad as a side
effect.
2017-05-01 16:44:56 -04:00
Hardik
6b7aef63ac Added support for multidimensional tensors in PReLU; Channel number now in second dimension 2017-03-22 20:36:52 -04:00
Martin Raison
f17cfe4293 sparse tensor operations (#735) 2017-03-03 18:37:03 +01:00
Sergey Zagoruyko
819d4b2b83 Add finite differences gradcheck (#851) 2017-02-26 08:35:24 -05:00
Adam Paszke
42633f8986 Fix misspelling and add support for weights in NLLLoss2d 2017-02-20 23:28:31 -08:00
Adam Paszke
7117a9012e Fix flaky non-contig test 2017-02-17 10:40:08 +05:30
Adam Paszke
63edca44f2 Add tests for non-contiguous inputs and gradients 2017-02-14 21:28:50 +01:00
Adam Lerer
fb2d28f477 remove circular references in NestedIOFunction 2017-01-28 23:30:06 +01:00
Luke Yeager
e7c1e6a8e3 [pep8] Fix most lint automatically with autopep8
Here's the command I used to invoke autopep8 (in parallel!):

    git ls-files | grep '\.py$' | xargs -n1 -P`nproc` autopep8 -i

Several rules are ignored in setup.cfg. The goal is to let autopep8
handle everything which it can handle safely, and to disable any rules
which are tricky or controversial to address. We may want to come back
and re-enable some of these rules later, but I'm trying to make this
patch as safe as possible.

Also configures flake8 to match pep8's behavior.

Also configures TravisCI to check the whole project for lint.
2017-01-28 01:15:51 +01:00
Adam Paszke
f8d4f980b3 Add upsampling modules and functions 2017-01-24 17:30:50 -05:00
Bobby De Simone
0048f228cb Add spatial test for LogSoftmax 2017-01-24 23:24:25 +01:00
Adam Paszke
95f0fa8a92 Change .grad attribute of Variables to be a Variable 2017-01-16 12:59:47 -05:00
Sam Gross
f0a6ca4d53 BatchNorm fixes (#423)
- don't use cuDNN for half inputs because weight, bias, running_mean,
   etc. are required to be of different type than for THCUNN
 - accept 3D inputs (N,C,L) in BatchNorm1d
 - remove accidental 'use_cudnn=False'
2017-01-09 13:16:51 -05:00
Adam Paszke
cd82b2b869 Implement comparison and logical operators for tensors 2016-12-28 00:04:08 +01:00
Adam Paszke
ae6f2dd11c Adapt nn code to changes in THNN and THCUNN 2016-11-15 23:02:14 +01:00
Sam Gross
15377ac391 Copy Module._buffers in nn.parallel.replicate (#180) 2016-10-31 12:12:29 -04:00
Adam Lerer
942ca477a6 Copying weights for CUDNN 2016-10-23 20:23:48 -07:00
Adam Lerer
1213149a2f add bias option to linear; allow modules to return nested lists/tuples of tensors (#106)
* add bias option to linear; allow modules to return nested lists/tuples of tensors
2016-10-06 15:59:12 -04:00
Adam Paszke
c8a4734b97 Add RReLU to both nn packages 2016-09-29 11:33:34 -07:00
Sam Gross
cb5d4e836f Lazy load CUDA and THNN modules (#64) 2016-09-28 19:29:53 -04:00
Adam Paszke
7f4ff0e615 Fix type conversions in nn 2016-09-27 15:45:49 -07:00
soumith
5107f23126 fix ClassNLLCriterion targets in tests and legacy nn 2016-09-26 18:56:12 -07:00
Adam Paszke
c51e2c8b8c Rename CELoss to CrossEntropyLoss 2016-09-23 18:06:44 -07:00
Adam Paszke
8fdec15a55 Codemod to remove camel case method naming 2016-09-20 08:40:28 -07:00
Adam Paszke
64a15928d7 Fix tests on python 3.3 2016-09-15 20:29:08 -07:00
Adam Paszke
d1fda539b7 Fix nn serialization errors 2016-09-15 19:28:34 -07:00
Adam Paszke
fb39971464 Add more modules to nn 2016-09-14 11:05:56 -07:00
Adam Paszke
f646391f26 Bug fixes and test improvements
Fixed:
* tensor and storage printing
* legacy.nn module printing
* SpatialCrosMapLRN tests

Also, all fixed bugs have regression tests now.
2016-09-08 19:07:05 -07:00
Sam Gross
cd0929aa5e Use chainer-style constructor for Conv2d
* Conv2d, MaxPool2d, and AvgPool2d have one argument for each of ksize,
   stride, and pad. This argument can be either a single number or a
   tuple of (h, w)
2016-09-07 15:51:44 -07:00
Sam Gross
959304bc0d Make BatchNorm2d inherit from BatchNorm 2016-08-30 13:25:01 -07:00
Sam Gross
ec22828169 Add torch.nn.AvgPool2d 2016-08-30 12:16:40 -07:00
Adam Paszke
cc645de37b MaxPooling2d -> MaxPool2d 2016-08-24 10:11:00 -07:00
Adam Paszke
ea93fb7ac0 Add more nn modules 2016-08-23 19:15:21 -07:00
Adam Paszke
d467a068c2 Add tests for new modules 2016-08-19 14:57:01 -07:00