Commit Graph

184 Commits

Author SHA1 Message Date
Vishwak Srinivasan
76a283db40 [ready] General Documentation Improvements - 2 (#5685)
* Fix some minor errors in existing docs.

* Fix Convolution and Pooling docs in torch.nn.functional

* Cleaned up torch.nn.functional docs

* Address @SsnL 's comments

* Add multiplication sign missing in docs

* Fix more typos, and clear some warnings

* Change infinity symbol in LPPool2d

* Revert some changes in torch.nn.functional

* Few more minor changes
2018-03-13 09:47:43 -04:00
li-roy
4c4a42b3f9 implement CosineEmbeddingLoss as a native function and add reduce arg (#5646)
* implement CosineEmbeddingLoss as a native function and add reduce=True arg to it

* fix flake8

* address comments

* add reference function to tests

* fix flake8
2018-03-08 17:54:24 -05:00
Edward Z. Yang
9de922991c
Revert "implement CosineEmbeddingLoss as a native function and add reduce arg" (#5640)
* Revert "implement CosineEmbeddingLoss as a native function and add reduce arg (#5447)"

This reverts commit c16478fe3f.
2018-03-08 14:07:17 -05:00
li-roy
c16478fe3f implement CosineEmbeddingLoss as a native function and add reduce arg (#5447)
forward (new) [1.1905965859768912, 1.160144692985341, 1.1558120870031416]
backward (new) [1.9150976981036365, 1.9792822760064155, 1.8779143309220672]
double backward (new) [3.6898688060464337, 3.5784677929477766, 3.569505032035522]

forward (old) [3.2359962839400396, 3.275224728975445, 3.3409753759624436]
backward (old) [5.668679727939889, 5.722980880062096, 5.585088661056943]
double backward (old) N/A

* implement CosineEmbeddingLoss as a native function and add reduce=True arg to it

* fix flake8

* address comments

* add reference function to tests

* fix flake8
2018-03-08 13:15:12 -05:00
Francisco Massa
0f50ca0b48 Add reduce to functional smooth_l1 documentation (#5610)
This has been present in master since https://github.com/pytorch/pytorch/pull/3382 but the doc for the functional interface was not taken into account.
2018-03-07 10:16:40 -05:00
cjsg
15eae9543e Fixed dimensions in docs of conv and conv_transpose (#5543) 2018-03-03 05:49:01 -05:00
Edward Z. Yang
f064c5aa33
Expunge all occurrences of torch._C._VariableFunctions (#5525)
Some of the call-sites now look a little hokey with this
removed, saving that for another patch.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2018-03-02 12:19:44 -05:00
Tongzhou Wang
27265503ad nn.* doc update after Variable/Tensor merge (#5459)
The nn.* counterpart of #5443 . Mostly removed Variable wrapper. Also added doc for nn.RReLU.

Notice that torch.randn(*, requires_grad=True) isn't documented until #5462 is done.
2018-03-01 18:11:39 -05:00
Soumith Chintala
36abf023bd
Added 3d grid sampler (for volumetric transformer networks) (#5453)
* add 3d grid_sample

* add cuda implementation, more testing
2018-02-28 19:32:15 -05:00
li-roy
5bbeb55f22 add reduce=True arg to MultiMarginLoss (#5150)
* add reduce=True arg to MultiMarginLoss

* Change tests to support legacy

* fix flake8

* address comments

* formatting change

* remove free of unallocated tensor

* fix after variable/tensor merge
2018-02-27 18:35:50 -05:00
Sam Gross
30ec06c140
Merge Variable and Tensor classes (#5225)
This replaces the torch.Tensor constructors with factories that produce
Variables. Similarly, functions on the torch module (e.g. torch.randn)
now return Variables.

To keep the PR to a reasonable size, I've left most of the unused tensor
code. Subsequent PRs will remove the dead code, clean-up calls to
torch.autograd.Variable, and rename Variable to Tensor everywhere.

There are some breaking changes because Variable and Tensors had
slightly different semantics. There's a list of those changes here:

 https://github.com/pytorch/pytorch/wiki/Breaking-Changes-from-Variable-and-Tensor-merge
2018-02-23 18:03:31 -05:00
Tongzhou Wang
1848cad108 [ready] Layer Normalization (#4922)
* at::maybe_data_ptr and Check.h => TensorUtils.h

* THNN support for optional BN running_*

* ATen support for optional BN running_*

* Python nn.* support for optional BN running_*; Improve IN and BN doc

* Add tests for IN and BN new option

* Layer Norm

* Fix LRN doc

* functional interface for LN and IN

* Layer norm tests

* fix BN double backward returning undefined tensors

* fix jit test using wrong dim inputs for BN

* add/improve BN, IN and LN GPU tests with half type

* Udpate docs to be consistent with Conv notation
Fix onnx
Clarified onnx symbokic wrapper

* fix typo

* Address comments
2018-02-22 11:56:41 -05:00
li-roy
68aed0779d add reduce=True arg to MultiLabelSoftMarginLoss (#5097)
* add reduce=True arg to MultiLabelSoftMarginLoss

* Move some tests to new_criterion_tests

* fix flake8

* fix multilabelsoftmarginloss weights test
2018-02-15 15:29:44 -05:00
Richard Zou
ab18aaeba7 Clarify output shapes of reduce=False losses (#5082) 2018-02-13 10:11:14 -08:00
li-roy
147612e64a add reduce=True arg to SoftMarginLoss (#5071)
* add reduce=True arg to SoftMarginLoss

* add reference function for SoftMarginLoss

* Rebase onto master

* Address comments

* Fix flake8

* Fix rebase error
2018-02-13 10:51:57 -05:00
cpuhrsch
07be53b57f Move EmbeddingBag into ATen (#4856)
This diff creates code related to EmbeddingBag in ATen. It also allows sparse gradients.
2018-02-12 14:20:32 -05:00
li-roy
ce5702fa80 add reduce=True arg to HingeEmbeddingLoss (#5130)
* add reduce=True arg to HingeEmbeddingLoss

* pass arg to super constructor in HingeEmbeddingLoss

* make HingeEmbeddingLoss reference fn work on legacy
2018-02-09 11:38:36 -05:00
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
Lu Fang
c111cdfd1d Add onnx support for InstanceNorm (#4626)
* Add ONNX symbolic for instancenorm

* Fix some bugs
2018-02-07 10:54:30 -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
fcccd07cc0
Implement hinge_embedding_loss as a native function. (#5080) 2018-02-06 14:43:36 -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
Richard Zou
e4ddbeb554 Fix typo (#4846) 2018-01-25 10:33:45 -05:00
Richard Zou
b997474a4f Adds Im2Col and Col2Im (#4729) 2018-01-19 09:37:53 -05:00
Sam Gross
57549b7e44
Bind functions with out= arguments in VariableType (#4565)
This adds overrides in VariableType for the xxx_out ATen functions and
implements Python bindings. There is no support for automatic
differentiation. If any of the inputs (or outputs) requires grad, then the
function will throw an exception unless it's running in "no-grad" mode.

The bindings for calling torch.xxx functions on Variables are moved to a
different object. Previously, they were static method on VariableBase.
This change prevents users from accidentally calling static methods as if
they were instance methods.
2018-01-17 18:27:42 -05:00
Sam Gross
cb83474a57
Fix embedding with sparse=True (#4686)
Fixes #4666
2018-01-16 16:19:20 -05:00
Kai Arulkumaran
2260649fb6 Local Response Normalization (#4667)
* Local Response Normalization

* Add 1D and 3D LRN

* Generalise LRN to higher dims

* Use mean instead of sum

Specify 'across-channels'
2018-01-15 22:23:51 -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
Riddhiman Dasgupta
f99c7d9429 Padding_idx in Embedding supports negative indexing (#4496) 2018-01-09 12:04:11 +01:00
Neeraj Pradhan
408c84de7c Supporting logits as parameters in Bernoulli and Categorical (#4448)
* Supporting logits as parameters in Bernoulli and Categorical

* address comments

* fix lint

* modify binary_cross_entropy_with_logits

* address comments

* add descriptor for lazy attributes

* address comments
2018-01-05 03:45: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
Hugh Perkins
fc0d940c5e add gumbel_softmax, based on Eric Jang's implementation (#3341)
* add gumbel_softmax, based on Eric Jang's implementation

* Make gumbel_softmax CUDA friendly

* gumbel_softmax tweaks
2018-01-04 12:23:21 -05:00
Sam Gross
20b5e82155
Implement embedding in ATen (#4322)
Implements nn.Embedding (lookup table) in ATen.

Breaking change: new optional argument padding_idx in F.embedding to
match nn.Embedding.

Note that there are a few bugs in Embedding that are inherited from the
previous code:

 - CUDA renorm has race conditions if index contains duplicate entries
 - sparse gradient doesn't work with scale_grad_by_freq
2018-01-02 15:44:46 -05:00
Sam Gross
98f71912b0
Fix type signature of in-place NN functions (#4389)
This is a step towards removing the special casing of NN functions in gen_variable_type.py. It fixes the signature of in-place NN functions so that they return Tensor & instead of Tensor.
2017-12-28 16:50:09 -05:00
Sam Gross
4dba674324
Move factional max pooling to ATen (#4290) 2017-12-21 17:07:46 -05:00
Edward Z. Yang
5f7c5502b8
Further improvements to ATen convolution (#4287)
- Rename THNN convolution to have thnn_ prefix.
- Propagate CuDNN benchmark and deterministic to at::Context
- Add 'convolution', 'convNd' and 'conv_transposeNd' native wrappers, with defaults
  The conv_transposeNd wrappers are updated to have the same argument
  order as Python.
- torch.nn.functional directly dispatches to the native wrappers
- Make it possible to turn off tracing for some native wrappers, so I don't
  have to write symbolics for all the functions above
- Spectral ops can now make use of CuDNN convolution if possible
- Better commentary on cudnn_batch_norm
- Turn on DCE for all JIT tests.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2017-12-21 13:03:43 -05:00
Edward Z. Yang
5b8fe5cbb5
Batchnorm in ATen (#4285)
* Batchnorm in ATen

This commit moves BatchNorm derivatives into ATen, eliminating
torch/csrc/autograd/functions/batch_normalization.cpp

Some refactoring along the way:

- Functions got renamed to remove _forward from their names
- CuDNN batchnorm forward was modified to return save_mean/save_std instead of
  take it as parameters. To avoid returning undefined Variables, these return
  (small) uninitialized tensors when they are not used.
- THNN batch normalization takes care of resizing save_mean and save_std on
  forward.
- There are some shenanigans re batchnorm backwards in eval mode. I'm tracking
  that in #4284
- I decided not to introduce buffers as a proper concept in ATen, which means
  that tensors like running_mean/running_var are variables in ATen.  This meant
  there needed to be some adjustments to how we *trace* such variables; the
  new strategy is if we can't find a Value for a variable, we look and see
  if we have a Value for the buffer pointed to by the variable, before
  finally falling back on constant.
- This PR finally reliably triggered OOM on Travis builds; I fixed this by reducing
  the number of parallel jobs.
- Stop using std::string when it's not necessary.
- Remove training parameter from cudnn_batch_norm_backward, because it
  doesn't make sense; cuDNN doesn't implement the math for evaluation mode
  batchnorm backwards.
- batchnorm_double_backward is now in an anonymous namespace, as it
  no longer needs to be called from torch/csrc

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2017-12-21 11:38:31 -05:00
Sam Gross
b6a30f7ede
Move SELU to ATen (#4269)
Fuse scale multiplication into ELU
2017-12-20 16:32:21 -05:00
Sam Gross
dad4b2d6cc
Move adaptive avg/max pool1d to ATen (#4266) 2017-12-20 15:50:17 -05:00
Sam Gross
689ef9cba3
Move upsampling to ATen (#4264) 2017-12-20 15:12:07 -05:00
Edward Z. Yang
a88a8ec827
Convolution derivatives in ATen (#4116)
* Convolution derivatives in ATen

This PR introduces ATen implementation of convolution, which dispatches to
THNN/CuDNN/nnpack based on input parameters. The general strategy is to compose
this function out of the various forward-backward pairs of specific
implementations, rather than write a monolithic function with backwards (which
is what we did before because the boilerplate of doing it otherwise would have
been very high.) The new API provides the following functions:

  - _convolution, which is a fully generic, native convolution implementation
    that dispatches to various other convolution implementations depending on
    input characteristics. This is prefixed with an underscore because it
    explicitly takes benchmark, deterministic and cudnn_enabled which are
    implementation details for CuDNN. The intent is to eventually provide a
    convolution that reads these parameters out of the context using #4104.
  - _convolution_nogroup is a convolution implementation for non-CuDNN
    algorithms which don't support group convolution natively.
  - _convolution_double_backward is the generic double-backwards implementation
    for convolution.

In more detail:

- Most functionality from torch/csrc/autograd/functions/convolution.cpp has been
  moved into aten/src/ATen/native/Convolution.cpp
- We continue to make use of ConvParams, but we now construct the parameters
  upon entry to a function from the function signature (which does not use
  ConvParams; having convolution take ConvParams directly would require teaching
  the code generator how to accept these as parameters, complicating ATen's API
  model) and destruct them when making subprocedure calls.
- I introduce a new idiom, input_r, which represents a const Tensor& reference,
  which will subsequently be assigned to a local Tensor input. This is helpful
  because a lot of the existing algorithms relied on being able to assign to
  locals, which is not permitted with a const reference.
- The native argument parser now supports std::array<bool,2> inputs (NB: there
  MUST NOT be a space; this is the same hack as is applied to derivatives.yaml)
- Native parser now supports Tensor? arguments, which indicates a nullable
  tensor. Previously this function was only used by NN methods.
- Documentation updates on THNN library
- I added an extra fgradInput argument to VolumetricConvolutionMM_updateOutput
  and VolumetricConvolutionMM_accGradParameters so that its buffer list lines up
  with the backward argument list. This makes it possible to write derivative
  for conv3d which previously was not supported (commented out in
  derivatives.yaml)
- Extra double_backward declarations for all convolution backwards functions was
  added.
- You can now use the syntax Tensor? in native_functions.yaml to indicate that a
  tensor argument is nullable.  There are adjustments to propagate this to the
  Python argument parser.
- NNPACK was ported to ATen, and ATen now builds and links against ATen if
  possible. New AT_NNPACK_ENABLED macro.  The nnpack functions are
  nnpack_spatial_convolution.
- Some modest CuDNN convolution refactoring to remove _forward from names.
- There's a new cudnn_convolution_backward function to deal with the fact that
  CuDNN convolution double backward requires you to have computed all gradients
  in one go.
- Variable set_flags now checks if the tensor is undefined, fixing a silent memory
  corruption.
- checkSameType updated to not raise an exception if called with Variable arguments
- "no ATen declaration found for" error message is improved to say what available declarations are
- make_variable now accepts undefined tensors, and returns an undefined tensor in this case.
2017-12-20 14:19:27 -05:00
Sam Gross
b476d10c64
Move max_pool1d to ATen (#4257) 2017-12-19 20:10:11 -05:00
Sam Gross
9495595520
Move reflection/replication padding to ATen (#4258) 2017-12-19 18:57:14 -05:00
Sam Gross
227ef1fb60
Move adaptive avg pooling 2d/3d to ATen (#4254)
Move adaptive avg pooling 2d/3d to ATen

Also use ATen for softshrink
2017-12-19 15:45:33 -05:00
James Reed
cb4f6c3148 conv_tbc (#3730)
attempt to rebase

skip conv_tbc in preprocess_nn_functions

Add conv_tbc symbolic

Fix backward issue with dBias

ConvTBC nn wrapper and unit test
2017-12-18 23:52:36 -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
Kevin Zakka
b86dc0c8ba add reduce arg to PoissonNLLLoss (#3770)
* add reduce arg to PoissonNLLLoss

* fixed comments except reference function

* fixed unit test

* small indentation fix

* fixing last comments by richard

* lint check

* another linting issue
2017-12-18 02:32:05 -05:00
Richard Zou
30e6898808 Implement NLLLossNd (#4035)
* Implement NLLLossNd

* Fix tests and typos

* Fix tests
2017-12-18 02:16:16 -05:00