Commit Graph

84 Commits

Author SHA1 Message Date
Adam Simpkins
81b9aa743b [pytorch] Update caffe2/python to eliminate Pyre errors (#52083)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52083

This makes minor fixes in `caffe2/python` to address all errors currently
reported by Pyre.

I update the code to fix errors when doing so looked simple and safe,
and added `pyre-fixme` comments in other places.
ghstack-source-id: 121109695

Test Plan: Confirmed that Pyre no longer reports errors under `caffe2/python`

Differential Revision: D26272279

fbshipit-source-id: b1eb19d323b613f23280ce9c71e800e874ca1162
2021-02-11 11:04:59 -08:00
Adam Simpkins
c4eb22009e Drop some Python 2 compatibility code (#51769)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51769

Remove some Python 2 compatibility code that otherwise causes errors to
be reported from static type checkers.

Static type checkers complain that the old Python 2 modules and
functions referenced by this code do not exist.  Given that Python 2
support is entirely deprecated now we can simply remove the
compatibility code.
ghstack-source-id: 121313191

Test Plan:
Was able to get Pyre to successfully type check the `caffe2/python`
directory with this and some other changes.

Reviewed By: Tianshu-Bao

Differential Revision: D26271723

Pulled By: simpkins

fbshipit-source-id: fec8a09466be6867388832380480aafd36616aa1
2021-02-11 11:02:33 -08:00
Bugra Akyildiz
27c7158166 Remove __future__ imports for legacy Python2 supports (#45033)
Summary:
There is a module called `2to3` which you can target for future specifically to remove these, the directory of `caffe2` has the most redundant imports:

```2to3 -f future -w caffe2```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/45033

Reviewed By: seemethere

Differential Revision: D23808648

Pulled By: bugra

fbshipit-source-id: 38971900f0fe43ab44a9168e57f2307580d36a38
2020-09-23 17:57:02 -07:00
Christopher Whelan
5cd0f5e8ec [PyFI] Update hypothesis and switch from tp2 (#41645)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/41645

Pull Request resolved: https://github.com/facebookresearch/pytext/pull/1405

Test Plan: buck test

Reviewed By: thatch

Differential Revision: D20323893

fbshipit-source-id: 54665d589568c4198e96a27f0ed8e5b41df7b86b
2020-08-08 12:13:04 -07:00
Andres Suarez
9ea9d1b52e [fbs][2/n] Remove .python3 markers
Test Plan:
`xbgr '\.python3'` shows only one (dead) usage of this file:
https://www.internalfb.com/intern/diffusion/FBS/browse/master/fbcode/python/repo_stats/buck.py?commit=9a8dd3243207819325d520c208218f6ab69e4e49&lines=854

Reviewed By: lisroach

Differential Revision: D22955631

fbshipit-source-id: e686d9157c08c347d0ce4acdd05bd7ab29ff7df5
2020-08-05 18:25:50 -07:00
Stanislau Hlebik
b774ce54f8 remediation of S205607
fbshipit-source-id: 798decc90db4f13770e97cdce3c0df7d5421b2a3
2020-07-17 17:19:47 -07:00
Stanislau Hlebik
8fdea489af remediation of S205607
fbshipit-source-id: 5113fe0c527595e4227ff827253b7414abbdf7ac
2020-07-17 17:17:03 -07:00
Nikita Shulga
952e0f00a4 Skip c2_ref_tests on network failures (#37972)
Summary:
Skip the tests if network is unaccessible and model can not be downloaded
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37972

Differential Revision: D21441996

Pulled By: malfet

fbshipit-source-id: 5ce59764584974aee9195572338ada1fa0351a75
2020-05-06 22:19:28 -07:00
James Reed
341fb6d11d Make caffe2/caffe2/python/models/seq2seq python3 compatible
Test Plan: watiforsadcastle

Reviewed By: dzhulgakov

Differential Revision: D19698403

fbshipit-source-id: 36b73e07e598c848abbe368e522484da9ba4c78f
2020-02-04 10:51:47 -08:00
Brian Wignall
e7fe64f6a6 Fix typos (#30606)
Summary:
Should be non-semantic.

Uses https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines to find likely typos.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/30606

Differential Revision: D18763028

Pulled By: mrshenli

fbshipit-source-id: 896515a2156d062653408852e6c04b429fc5955c
2019-12-02 20:17:42 -08:00
Abhinav Jauhri
f93e0619f3 Adding ShufflenetV2 to caffe2's benchmark suite. (#20180)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20180

Adding ShufflenetV2 (by Ma et. al. 2018) to the caffe2's benchmark
suite.

To run, use: `buck run mode/opt caffe2/caffe2/python/examples:imagenet_trainer -- --train_data null --batch_size 128 --epoch_size 3200 --num_epochs 2 --num_gpus 2 --model shufflenet`

Reviewed By: bddppq, xw285cornell

Differential Revision: D15094282

fbshipit-source-id: 0e1ce9c5975868e917b0f179e2c5b15647a76b4e
2019-05-23 20:40:17 -07:00
Michael Antonov
7655b857f7 Add debug logic to c2_ref_test and its helpers (#19359)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/19359

Even with file IO exception handling, some of the sandcastle c2_ref_tests are still failing in length-check assert, as can be seen here:
https://our.intern.facebook.com/intern/test/844424932589974?ref_report_id=0

This is an attempt to add printing logic to debug what's going on.

Reviewed By: dzhulgakov

Differential Revision: D14966274

fbshipit-source-id: adce6d4780d664c5ef59f9341b6133b0d09324cb
2019-04-22 12:08:55 -07:00
Min Ni
c3e3c5cc39 Skip tests if C2/ONNX models cannot be read (#18494)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18494

Today we have some C2 end2end test run requiring reading model data from external filesystem (for example, Gluster and AWS). This could be a source for flaky test when the external filesystems are not reachable during the tests.

In this diff, we add try/catch logic around where we download models and open model files from external system. In case such attempts fails, we will catch the excption and let the unittest skip the current test instead of failure.

I also refactor the code a little bit by removing some duplicated logic on downloading and build the c2 model data. It has been duplicated in two classes and a few functions...

Reviewed By: yinghai

Differential Revision: D14442241

fbshipit-source-id: da8bf56c8d096efa34ca2070de5cd10a18aad70c
2019-03-27 11:21:44 -07:00
ttup7777
54ef852d7f Fix unclosed files in download.py, test_onnxifi.py, test_trt.py (#18017)
Summary:
According to https://docs.python.org/3/tutorial/inputoutput.html, it is good practice to use the "with" keyword when dealing with file objects. If not, you should call f.close() to close the file and immediately free up any system resources used by it.  Thus, I adjust the open file function to "with open() as f".
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18017

Differential Revision: D14475112

Pulled By: ezyang

fbshipit-source-id: d1c0821e39cb8a09f86d6d08b437b4a99746416c
2019-03-15 07:29:46 -07:00
rohithkrn
0d663cec30 Unify cuda and hip device types in Caffe2 python front end (#14221)
Summary:
Goal of this PR is to unify cuda and hip device types in caffe2 python front end.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14221

Differential Revision: D13148564

Pulled By: bddppq

fbshipit-source-id: ef9bd2c7d238200165f217097ac5727e686d887b
2018-11-29 14:00:16 -08:00
Xiaodong Wang
eb7a298489 Add resnext model to OSS (#11468)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/11468

Add resnext model into OSS Caffe 2 repo.

Reviewed By: orionr, kuttas

Differential Revision: D9506000

fbshipit-source-id: 236005d5d7dbeb8c2864014b1eea03810618d8e8
2018-09-12 15:59:20 -07:00
Pritam Damania
5bd43a7af8 Refactor Seq2SeqModelCaffe2EnsembleDecoder (#10035)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/10035

This is an initial diff which refactors some of the components in the Seq2SeqModelCaffe2EnsembleDecoder class.

Reviewed By: jmp84

Differential Revision: D9026372

fbshipit-source-id: 449635208f24494209ae2fb78a19fca872970ea8
2018-07-31 23:09:09 -07:00
Yinghai Lu
e9f6f14555
[Caffe2] Revamp the convnet benchmark code by using models from model zoo (#7351)
* Revamp the convnet benchmark code by using models from model zoo

* Move ModelDownloader to caffe2/python/models

* Remove convnet_benchmarks.py
2018-05-08 08:53:52 -07:00
Orion Reblitz-Richardson
1d5780d42c Remove Apache headers from source.
* LICENSE file contains details, so removing from individual source files.
2018-03-27 13:10:18 -07:00
Yinghai Lu
efe1c2bd13 hypen as a valid part of model names (#2312) 2018-03-20 08:52:54 -07:00
jmp84
b465bb9a8e fix post eos penalty (#2235) 2018-03-12 12:42:22 -07:00
PengBo
07646e405e no_bias in resnet32x32 (#1817) 2018-02-24 16:58:23 -08:00
Junjie Bai
b11ba65204 Experimental support for setup.py develop mode install
Summary:
`python setup.py develop` / `pip install -e .`
Closes https://github.com/caffe2/caffe2/pull/1926

Reviewed By: orionr

Differential Revision: D6951780

Pulled By: bddppq

fbshipit-source-id: 01249cbca90ec5326ea4107d4e500ae95a9dbd7b
2018-02-12 23:36:18 -08:00
Alexander Sidorov
e0e124e617 Fix RNN scoping situation
Summary:
There is a long lasting problem of scoping which was introduced in original python wrappers early in H1. Basically each RNNCell implemented has to manually scope outputs of each of the operators. If somebody forgets, then there could be weird bugs with layers etc.

Approach is the following. User has to explicitly specify current scope when using  apply_over_sequence function and others if the function is going to be called several times (like for stacking layers). This way we use Caffe2 native scoping approach instead of inventing one extra API people have to use (i.e. passing scope name as an argument to the RNNCell constructor).
Closes https://github.com/caffe2/caffe2/pull/1681

Differential Revision: D6777536

Pulled By: salexspb

fbshipit-source-id: 73d860b8d4857589e04bdea5a6fcd3080d68427c
2018-02-07 17:35:29 -08:00
Orion Reblitz-Richardson
d3ea7e260b Allow for all of the names we have in our model zoo.
Summary:
* We now allow subdirectories as well as numbers in the name.
* Also fixed an error case.
Closes https://github.com/caffe2/caffe2/pull/1875

Reviewed By: pjh5

Differential Revision: D6894401

Pulled By: orionr

fbshipit-source-id: 6a9938bc7d2ba6b8f094ed7b8a02664120a10626
2018-02-05 08:52:55 -08:00
Di Yu
82198831e7 Fix pool op custom path issue 2, wrongful routing to global pooling
Summary:
In D5681122 - when routing to global maxpool and average pool, the condition is not correct.
see T24876217 for discussion

Reviewed By: Yangqing

Differential Revision: D6665466

fbshipit-source-id: dcb5b4686249e6ee8e1e976ab66b003ef09b32fd
2018-01-09 00:54:45 -08:00
Ves Stoyanov
1a0eefd5fc Parallelize batcher
Summary: Still WIP, but works for the universal encoder. The other ones are currently broken.

Differential Revision: D6492786

fbshipit-source-id: 232e0058eb3a0c036de3adf0295db5efd624cca7
2017-12-22 20:23:26 -08:00
Martin Schatz
f233a3ebd8 Explicitly set default data type in seq2seq/translate.py
Summary: word_rewards data type is mixed; ConstantFill assigns long but later is filled with float32.  This causes issues when running net from outputted protobuf.  This change makes data type to be float32 for lifetime of blob.

Reviewed By: jhcross

Differential Revision: D6486723

fbshipit-source-id: c4ce5185a0a6d71b08b1819f2355e9354823b701
2017-12-07 11:21:01 -08:00
Simon Layton
a8250280bb Py3 test fixes
Summary:
\cc pietern
Closes https://github.com/caffe2/caffe2/pull/1555

Differential Revision: D6479902

Pulled By: pietern

fbshipit-source-id: 84647eddec45620b1ed603f4882ded2dd49adc43
2017-12-05 10:34:41 -08:00
James Cross
65a1dbc93d penalty for EOS successor
Summary: Current beam search generates successor states to EOS which are considered for inclusion in the beam even though they do not represent valid sequence prefixes. This diff introduces a penalty to ensure that such states are not included in the beam.

Reviewed By: xliilx

Differential Revision: D6325511

fbshipit-source-id: b17f10b0d00f3bc5fcc5a826a8a57a0f2cb360a6
2017-11-14 21:46:56 -08:00
Aapo Kyrola
b5c053b1c4 fix fp16 issues with resnet trainer
Summary:
My commit  bab5bc  broke things wiht fp16 compute, as i had tested it only with the null-input, that actually produced fp32 data (even dtype was given as float16). Also, I had confused the concepts of "float16 compute" and fp16 data. Issue #1408.

This fixes those issues, tested with both Volta and M40 GPUs. Basically restored much of the previous code and fixed the null input to do FloatToHalf.

Reviewed By: pietern

Differential Revision: D6211849

fbshipit-source-id: 5b41cffdd605f61a438a4c34c56972ede9eee28e
2017-11-01 13:30:08 -07:00
James Cross
397793d61c simplify beam search code
Summary: This cleans up the _hack_get_slice_end() using the Conditional operator.

Reviewed By: jmp84

Differential Revision: D6177797

fbshipit-source-id: 5ce0b76b8472123415bba39488aa2c69aad96111
2017-10-31 16:59:20 -07:00
Aapo Kyrola
86e3e008e0 optimize RNN executor subnet construction for forward-only models
Summary:
RNN executor had a disadvantage to plain nets when running in forward-only mode: for plain nets, we only create two workspaces and two nets and alternate between them. With RNN executor, we had only four workspaces (4 > 2 because it was faster in some cases), but the nets (or rather the ops) were created for each of the timesteps. This has significant overhead. This diff changes this sos that if executor is is forward-only mode (i.e has limited parallelism setting), then it will use the same operators as the t - 4'th net -- excluding the ops that require the timestep blob. The latter exception is required because RNN executor needs different timestep blob for each timestep because it cannot modify the value of the timestep blob like when running nets in a loop.

Also removed redundancy in the dependency computation and added a debug flag to the executor that outputs the description of the rnn contents.

Reviewed By: salexspb

Differential Revision: D6155510

fbshipit-source-id: c47f727d2128649b081270d15020a08d41e5748d
2017-10-30 12:24:12 -07:00
Aapo Kyrola
63297e1a1f RunNetOnce->RunNet (removes rnn_executor overhead)
Summary:
seq2seq/translate.py was running much slower on RNNExecutor. This was because RNNExecutor has significant init overhead (I have another diff to reduce, but not completely eliminate it), and translate was calling the decoder with RunNetOnce -- thus always recreating the net and the ops. Changhing this to RunNet() makes translate run faster than without executor. RunNet uses the net name and uses the already created net, while RunNetOnce passes the whole protobuffer.

Noticed similar bug in seq2seq ensemble bean model, which also calls CreateNet() but uses RunNetOnce() instead of RunNet().

Reviewed By: jhcross

Differential Revision: D6156566

fbshipit-source-id: a933453e36a0d8fd163d0584186fda427a680687
2017-10-25 22:06:02 -07:00
Aapo Kyrola
241b9f6c14 disable rnn executor for beam search
Summary:
RNN executor has significant overhead of creating the timestep-nets the first time, and this is especially bad with beamsearch that is complex.
So disable RNN executor for now until perf regression is fixed (I have pending diff on it).

Reviewed By: salexspb

Differential Revision: D6138878

fbshipit-source-id: ce63ab9ce9cc1c0f67097aea1e370494ca98c680
2017-10-24 20:49:56 -07:00
Aapo Kyrola
1b71bf1d36 Updated resnet50_trainer and resnet for more FP16 support
Summary: Added FP16SgdOptimizer to resnet50_trainer

Reviewed By: wesolwsk

Differential Revision: D5841408

fbshipit-source-id: 3c8c0709fcd115377c13ee58d5bb35f1f83a7105
2017-10-24 09:19:06 -07:00
Dmytro Dzhulgakov
2972a6ca02 Revert D6026557: [caffe2][PR] Fix "No handlers could be found for logger"
Summary:
This reverts commit 95c634872ac02be721257169e38c8fead04cd66b

bypass-lint

Differential Revision: D6026557

fbshipit-source-id: 663c28583ce3b01070ff5449115ed7e222f71776
2017-10-12 20:21:52 -07:00
Luke Yeager
75bece6ede Fix "No handlers could be found for logger"
Summary: Closes https://github.com/caffe2/caffe2/pull/1316

Differential Revision: D6026557

Pulled By: Yangqing

fbshipit-source-id: 95c634872ac02be721257169e38c8fead04cd66b
2017-10-10 22:32:13 -07:00
Andrey Malevich
e13f199452 Switch RNNOp to use NetDef argument for step represenetation.
Summary: Before this diff RNNOp was using TextFormat for representing steps. This diff is changing RNNOp to prefer NetDef argument instead. To be backward compatible it supports TextFormat for existing models, though we can compile RNNs without TextFormat as well.

Reviewed By: salexspb

Differential Revision: D5949330

fbshipit-source-id: 9336a8f5ccf30ad8d8e3a7067b9437e1704b1c9f
2017-10-10 22:01:51 -07:00
Yangqing Jia
8286ce1e3a Re-license to Apache
Summary: Closes https://github.com/caffe2/caffe2/pull/1260

Differential Revision: D5906739

Pulled By: Yangqing

fbshipit-source-id: e482ba9ba60b5337d9165f28f7ec68d4518a0902
2017-09-28 16:22:00 -07:00
Junjie Bai
d9b0bcd7a4 Make all existing (except in RoIPool) "is_test" arguments required
Reviewed By: akyrola

Differential Revision: D5830168

fbshipit-source-id: 8634e9cfe308ba0ee90cd8a5c4b09a47b0b5f015
2017-09-25 23:46:12 -07:00
James Reed
ab62a92dab De-dup beam search state reshape shape blob
Summary:
T22119644 showed that there is a potential illegal memory access in beam search with attention. Upon further inspection, we can see that there are multiple ops that write to the same old shape blob:

  {"output0": "model0/attention_decoder/attention_weighted_encoder_context_reshaped", "output1": "state_old_shape_before_choosing_per_hypo", "input0": "model0/attention_decoder/attention_weighted_encoder_context" }},
  {"output0": "model0/attention_decoder/hidden_t_external_reshaped", "output1": "state_old_shape_before_choosing_per_hypo", "input0": "model0/attention_decoder/hidden_t_external" }},
  {"output0": "model0/decoder/layer0/cell_t_reshaped", "output1": "state_old_shape_before_choosing_per_hypo", "input0": "model0/decoder/layer0/cell_t" }},

This diff de-dupes these outputs

Reviewed By: akyrola

Differential Revision: D5899103

fbshipit-source-id: 8b6f3f113e764dfeb9262f6c442e1124559cd2d8
2017-09-23 23:19:44 -07:00
James Reed
0d6baa0d59 Fix lack of data dependencies for beam search RecurrentNetwork op
Summary: Previously, the RecurrentNetwork op used for our beam search did not have any of the input blobs listed as data dependencies. This was fine when we were using SimpleNet, since the ops were run in the order in which we added them to the graph, and thus the RecurrentNetwork op was run after all the other ops. However, when switching to DAG, the ops that produce input data for the beam search were being run in parallel with the RecurrentNetwork beam search op, which caused non-deterministic failures based on thread scheduling. This fixes that

Reviewed By: jmp84, jhcross

Differential Revision: D5879622

fbshipit-source-id: b622de1f6a24b2636b191096db92990e0535890c
2017-09-22 12:18:20 -07:00
Junjie Bai
c231ac2253 Add an argument for suppressing download progress
Summary: In some cases (e.g. CI), showing progress bar will mess up the log.

Reviewed By: jerryzh168

Differential Revision: D5850918

fbshipit-source-id: 2da9d020832264cef977391dc2fd8d1e2677d159
2017-09-17 20:15:51 -07:00
Junjie Bai
86a9a06878 HTTPMessage in Python 3 does not have getheader
Summary: get and getheader are the same in Python 2

Reviewed By: akyrola

Differential Revision: D5836486

fbshipit-source-id: 3bacfccc872c44741d7f26c68ba967093fce45c2
2017-09-14 13:59:06 -07:00
Xian Li
68e7a0f2ed Enable target dialect token in inference.
Differential Revision: D5665714

fbshipit-source-id: 56ba88e72f71cae23d992e3ad7ea134c3d2c6d1d
2017-09-12 17:22:18 -07:00
Xian Li
a782858285 Move go_token_id out of beam search constructor.
Summary: This is will allow the same decoder to handle different go tokens.

Differential Revision: D5801811

fbshipit-source-id: ddd309963c97e32c728b15d2ccd4ba0c4ad5ebbe
2017-09-11 18:52:08 -07:00
Aapo Kyrola
45f07238f4 make rnn executor figure out recurrent mappings from links
Summary: RNN executor previously relied on getting the mapping from x to x_prev (and gradients) from recurrent.py, but we can just infer them from links. This makes all models compatible with rnn executor, given enable_rnn_executor=1 argument.

Reviewed By: jamesr66a

Differential Revision: D5801436

fbshipit-source-id: 14d0e26dfbad6347f645d907da493187c98e9b17
2017-09-09 16:19:26 -07:00
James Cross
4758bd851b rectify args btw. train and translate
Summary: Make the command-line arguments pertaining to model architecture the same as between train.py and translate.py. Also use s() scoping function for all intermediate blobs in attention.py (this is for comatibility with multi-headed attention).

Differential Revision: D5594312

fbshipit-source-id: cadf51d854b5a9174ec913f32c655be2abf111e5
2017-08-10 15:27:18 -07:00
Aaron Markham
784ba07bf3 updated downloader to use s3 url without a redirect via the vanity url
Summary:
Model downloader was broken after the move on s3 to the vanity url, download.caffe2.ai. Using this as the url base hits a redirect, and will result in the script throwing a 403 error.  Rather than upgrading to urllib2 or putting in a bunch of code to handle a redirect on urllib, we can just use the non-vanity base url.
Closes https://github.com/caffe2/caffe2/pull/1020

Reviewed By: Yangqing

Differential Revision: D5568686

Pulled By: aaronmarkham

fbshipit-source-id: d88a6b3e1b7955835fc03b036dc54dec48316e7f
2017-08-09 12:25:30 -07:00