Commit Graph

250 Commits

Author SHA1 Message Date
Aaron Gokaslan
b1e8e01e50 [BE]: Apply PYI autofixes to various types (#107521)
Applies some autofixes from the ruff PYI rules to improve the typing of PyTorch. I haven't enabled most of these ruff rules yet as they do not have autofixes.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/107521
Approved by: https://github.com/ezyang
2023-08-20 02:42:21 +00:00
cyy
483f748dd5 [BE] Enforce missing override keyword (#104032)
This PR enables `-Winconsistent-missing-destructor-override` and `-Winconsistent-missing-override`
and fixes violations.

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 47e904e</samp>

This pull request updates the code of various classes and operators in the `caffe2` and `aten` subdirectories to use the `override` specifier instead of the `virtual` keyword for destructors and other virtual functions that override a base class function. This improves the code readability, quality, and consistency with C++ best practices. It also modifies the `./CMakeLists.txt` file to enable warnings for these specifiers, but disable errors.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/104032
Approved by: https://github.com/malfet
2023-06-24 02:34:24 +00:00
PyTorch MergeBot
b5594f7df0 Revert "Use missing-prototypes in torch_cpu (#103725)"
This reverts commit 716b3b893d.

Reverted https://github.com/pytorch/pytorch/pull/103725 on behalf of https://github.com/osalpekar due to Broke caffe2 builds due. More info at [D46920675](https://www.internalfb.com/diff/D46920675) ([comment](https://github.com/pytorch/pytorch/pull/103725#issuecomment-1603129273))
2023-06-22 18:30:31 +00:00
cyy
716b3b893d Use missing-prototypes in torch_cpu (#103725)
This PR enables  Wmissing-prototypes in torch_cpu except some generated cpp files and the mps and metal backends.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/103725
Approved by: https://github.com/albanD
2023-06-21 13:19:55 +00:00
Yun Wang (Speech)
4130e4f284 [hypothesis==6.70.1] Fix more test errors (#98685)
Summary:
This diff fixes more test failures (T150117218) caused by upgrading the "hypothesis" library to 6.70.1 (D44523679).

# //caffe2/caffe2/python:hypothesis_test
This test generates float numbers and filters out those whose absolute values are less than 1e-2.
It is a known issue of the new version of "hypothesis" that it generates zeros or floats with small absolute values too often:
https://github.com/HypothesisWorks/hypothesis/issues/3603
I'm circumventing this issue by suppressing the health check `filter_too_much`.

# //caffe2/caffe2/quantization/server:resize_nearest_dnnlowp_op_test
All arithmetic should be done in float32 when calculating the reference, since the network being tested uses float32 everywhere.
Mixing float32, float64 or even integers will result in intermediate values in float64.
The different precision may cause off-by-1 errors when converting to integer.

Test Plan:
Run all the tests in both "dev" and "opt" modes:
```
for mode in dev opt; do
  buck2 test mode/$mode //caffe2/caffe2/python:hypothesis_test -- --run-disabled
  buck2 test mode/$mode //caffe2/caffe2/quantization/server:resize_nearest_dnnlowp_op_test -- --run-disabled
  buck2 test mode/$mode //caffe2/caffe2/fb/layers/tests:tum_history_test -- --run-disabled
  buck2 test mode/$mode //caffe2/caffe2/fb/dper/layer_models/tests:nn_ops_test -- --run-disabled
  buck2 test mode/$mode //caffe2/caffe2/fb/metrics:metrics_test -- --run-disabled
  buck2 test mode/$mode //deeplearning/numeric_suite/toolkit/test:net_transform_test -- --run-disabled
  buck2 test mode/$mode //f3/type_system:tests -- --run-disabled
done
```

**NOTE:** In the first test (`//caffe2/caffe2/python:hypothesis_test`), the two methods `test_constant_fill_from_tensor` and `test_recurrent` would crash.
But these crash on hypothesis 5.49.0, too, so I'm leaving them alone.

Differential Revision: D44812706

Pull Request resolved: https://github.com/pytorch/pytorch/pull/98685
Approved by: https://github.com/malfet
2023-04-11 19:07:55 +00:00
Kazuaki Ishizaki
daff5d3556 Fix typos under caffe2 directory (#87840)
This PR fixes typos in `.md` files under caffe2 directory

Pull Request resolved: https://github.com/pytorch/pytorch/pull/87840
Approved by: https://github.com/kit1980
2022-10-28 04:53:36 +00:00
Pallab Bhattacharya
08c03c91d7 guard include of x64 intrinsics headers (#83793)
Summary: make inclusion of immintrin.h only for x64

Test Plan: CI

Differential Revision: D38886597

Pull Request resolved: https://github.com/pytorch/pytorch/pull/83793
Approved by: https://github.com/ajtulloch
2022-08-20 12:29:02 +00:00
Will Constable
4f34cd6d1e Replace all CHECK_ and DCHECK_ with TORCH_* macros (#82032)
Avoid exposing defines that conflict with google logging, since this blocks external usage of libtorch in certain cases.

All the 'interesting' changes should be in these two files, and the rest should just be mechanical changes via sed.
c10/util/logging_is_not_google_glog.h
c10/util/logging_is_google_glog.h

Fixes https://github.com/pytorch/pytorch/issues/81415

cc @miladm @malfet
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82032
Approved by: https://github.com/soumith, https://github.com/miladm
2022-07-26 01:20:44 +00:00
Nikita Shulga
f6c275f55d Remove -Wno-unused-variable from utils.cmake (take 2) (#75538)
Summary:
[Comment](https://github.com/pytorch/pytorch/pull/62445/files#r680132022) claims, it got added for consistency with  top level CMakeLists.txt, but `-Wno-unused-variable` is not mentioned there.

Modify violations in 50+ files that were added in the interim by either removing unused variables, or decorating the code with `C10_UNUSED` if local variable is likely used to extend object lifetime until the end of the block.

Caused preventable revert in https://github.com/pytorch/pytorch/pull/72633#issuecomment-1092300787

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

Reviewed By: anjali411

Differential Revision: D35747333

Pulled By: malfet

fbshipit-source-id: 3fc5828e44a4c05ba0e89e92613e6ebbdb260626
(cherry picked from commit c179fba21cfa2a0093fad50ccad5a22dd7cff52c)
2022-04-20 17:41:59 +00:00
PyTorch MergeBot
5c56b2286b Revert "Remove -Wno-unused-variable from utils.cmake"
This reverts commit 018cbe1f5c.

Reverted https://github.com/pytorch/pytorch/pull/75538 on behalf of https://github.com/seemethere
2022-04-19 17:19:09 +00:00
Nikita Shulga
018cbe1f5c Remove -Wno-unused-variable from utils.cmake
[Comment](https://github.com/pytorch/pytorch/pull/62445/files#r680132022) claims, it got added for consistency with  top level CMakeLists.txt, but `-Wno-unused-variable` is not mentioned there.

Modify violations in 50+ files that were added in the interim by either removing unused variables, or decorating the code with `C10_UNUSED` if local variable is likely used to extend object lifetime until the end of the block.

Caused preventable revert in https://github.com/pytorch/pytorch/pull/72633#issuecomment-1092300787

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75538
Approved by: https://github.com/cpuhrsch
2022-04-19 15:26:55 +00:00
Marc Fisher
9e60b00316 Remove AutoHeaders.RECURSIVE_GLOB from caffe2/ (#73227)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/73227

Reviewed By: christycylee

Differential Revision: D34016914

fbshipit-source-id: 277937f3c13a54ea1180afac253ee9927e56e99e
(cherry picked from commit d97777318170a406d89755e577386cde857dd59b)
2022-03-01 19:31:44 +00:00
Jongsoo Park
52b707b537 [dnnlowp] fix qparam handling during bias quantization (#73478)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73478

temp_qparams is not used and while constructing it accessing non-existent qparams

Test Plan: buck test mode/dev -c fbcode.platform=platform010 //caffe2/caffe2/quantization/server:conv_groupwise_dnnlowp_acc16_op_test -- --exact 'caffe2/caffe2/quantization/server:conv_groupwise_dnnlowp_acc16_op_test - test_groupwise_dnnlowp_conv_acc16_outlier (caffe2.caffe2.quantization.server.conv_groupwise_dnnlowp_acc16_op_test.GroupWiseDNNLowPOpConvAcc16OpTest)'

Reviewed By: jiyuanzFB

Differential Revision: D34502856

fbshipit-source-id: aeaa5c3aa76a2fb01d9565ee294a0c627418f55e
(cherry picked from commit 9f930156b3823d7f0676e26ebd4d0ae1e682f08b)
2022-03-01 03:38:54 +00:00
Xiao Sun
1436507960 fused int8 static (#73452)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73452

Added a fused Int8FC path using PackAWithQuantRowOffset like the INT8 dynamic path. There are two ways to enable it
(1) set an positive "X_scale" value in the arg list of Int8FC op
(2) send both "Qparam" (for output requantization, could be dummy values) and "in_Qparam" (for fused input quantization)

Differential Revision: D34034681

fbshipit-source-id: f25ca8a2b783ea597389d31c110448d19610218e
(cherry picked from commit 6fa10ba0e3be2d46298b439fba0fe9ae7e329f3a)
2022-02-28 16:34:45 +00:00
Jongsoo Park
cc55da8a9b [caffe2/server quant] use new depthwise conv fbgemm interface (#71166)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71166

Remove the use of deprecated old interface

Test Plan: CI

Reviewed By: jiyuanzFB

Differential Revision: D33533494

fbshipit-source-id: 930eb93cd67c7a9bb77708cc48914aa0c9f1c841
2022-01-12 15:29:07 -08:00
Richard Barnes
1622546050 use irange for loops (#70248)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70248

Modified loops in files under fbsource/fbcode/caffe2/ from the format
```
for(TYPE var=x0;var<x_max;x++)
```
to the format
```
for(const auto var: irange(xmax))
```

This was achieved by running r-barnes's loop upgrader script (D28874212) with some modification to exclude all files under /torch/jit and a number of reversions or unused variable suppression warnings added by hand.

Test Plan: Sandcastle

Reviewed By: malfet

Differential Revision: D32813863

fbshipit-source-id: 527244b4a2b220fdfe7f17dee3599603f492a2ca
2022-01-06 23:14:29 -08:00
Haixin Liu
6623c4838e Handle the corner case when min == max in L2 search (#70207)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70207

In corner case when min == max, adjust_hist_to_include_zero() function used in L2 search will cause additional_nbins = -2147483648 and initialize bins_f with negative size.

Test Plan:
Before fix:
f315187213

After fix:
f315471862

Reviewed By: jspark1105

Differential Revision: D33227717

fbshipit-source-id: 7e8a455e51a0703a3a9c5eb7595d9b4d43966001
2021-12-20 17:46:55 -08:00
Ramanpreet Nara
f587267dc7 Revert D31705359: use irange for loops 8
Test Plan: revert-hammer

Differential Revision:
D31705359 (17e5200441)

Original commit changeset: c9ea2fbc0f9c

fbshipit-source-id: 08fff2d12beca953ad30dd0baabf86e39ac84f14
2021-12-02 12:55:08 -08:00
Richard Barnes
17e5200441 use irange for loops 8 (#66743)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66743

Modified loops in files under fbsource/fbcode/caffe2/ from the format

`for(TYPE var=x0;var<x_max;x++)`

to the format

`for(const auto var: irange(xmax))`

This was achieved by running r-barnes's loop upgrader script (D28874212) with some modification to exclude all files under /torch/jit and a number of reversions or unused variable suppression warnings added by hand.

Test Plan: Sandcastle

Reviewed By: malfet

Differential Revision: D31705359

fbshipit-source-id: c9ea2fbc0f9cd29e97a52dcb203addc5f2abb09b
2021-12-02 10:21:29 -08:00
Stephen Macke
27cc11226d make broadcast fastpath the default for currently rolled-out ops (#68365)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68365

title. broadcast fastpath has been running fine for the enabled ops for a while now, so make it the default for these ops.

Test Plan: diff is a no-op, so sandcastle

Differential Revision: D32107847

fbshipit-source-id: b239b127b219985bf7df6a0eea2d879b8e9c79a4
2021-11-15 21:41:57 -08:00
Xue Li
2f099c7555 Revert D30652629: use irange for loops
Test Plan: revert-hammer

Differential Revision:
D30652629 (687c2267d4)

Original commit changeset: 0ae6c4bbbb55

fbshipit-source-id: 5c4f067b584a021c8c9656454d1ee60999600fb3
2021-10-15 15:23:10 -07:00
Richard Barnes
687c2267d4 use irange for loops (#66234)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66234

Modified loops in files under fbsource/fbcode/caffe2/ from the format

`for(TYPE var=x0;var<x_max;x++)`

to the format

`for(const auto var: irange(xmax))`

This was achieved by running r-barnes's loop upgrader script (D28874212) with some modification to exclude all files under /torch/jit and a number of reversions or unused variable suppression warnings added by hand.

bypass_size_limit
allow-large-files

Test Plan: Sandcastle

Reviewed By: ngimel

Differential Revision: D30652629

fbshipit-source-id: 0ae6c4bbbb554bad42e372792a6430e1acf15e3e
2021-10-15 13:50:33 -07:00
Nikita Shulga
4c4525fa5c Compile without -Wno-unused-variable (take 2) (#66041)
Summary:
Delete `-Wno-unused-variable` from top level `CMakeLists.txt`
Still suppress those warnings for tests and `torch_python`

Delete number of unused variables from caffe2 code
Use `(void)var;` to suppress unused variable in range loops
Use `C10_UNUSED` for global constructors and use `constexpr` instead of `static` for global constants

Do not delete `caffe2::OperatorBase::Output` calls as they have side effects

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

Reviewed By: ngimel

Differential Revision: D31360142

Pulled By: malfet

fbshipit-source-id: 6fdfb9f91efdc49ca984a2f2a17ee377d28210c8
2021-10-04 20:39:39 -07:00
Nikita Shulga
e4ee5ca698 Revert D31326599: [pytorch][PR] Compile without -Wno-unused-variable
Test Plan: revert-hammer

Differential Revision:
D31326599 (a6280ab653)

Original commit changeset: 924155f1257a

fbshipit-source-id: b8ee5bc0298637443232f5ee9ec79e51ed256faf
2021-10-01 20:40:47 -07:00
Nikita Shulga
a6280ab653 Compile without -Wno-unused-variable (#65954)
Summary:
Delete `-Wno-unused-variable` from top level `CMakeLists.txt`
Still suppress those warnings for tests and `torch_python`

Delete number of unused variables from caffe2 code
Use `(void)var;` to suppress unused variable in range loops
Use `C10_UNUSED` for global constructors and use `constexpr` instead of `static` for global constants

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

Reviewed By: ngimel

Differential Revision: D31326599

Pulled By: malfet

fbshipit-source-id: 924155f1257a2ba1896c50512f615e45ca1f61f3
2021-10-01 17:40:47 -07:00
Jongsoo Park
d6d286f651 [dnnlowp] reduce num of test cases to avoid time out (#64935)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/64935

As title

Test Plan: CI

Reviewed By: dskhudia

Differential Revision: D30889157

fbshipit-source-id: 316c808806b084bd2e44c56e1cdb61adf2369a9d
2021-09-14 21:32:12 -07:00
Stephen Macke
9f9244aabe [dte] scaffolding for c2 operator broadcasting fastpath (1/x) (#62369)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/62369

This diff is a big no-op that just sets up scaffolding for passing the "allow_broadcast_fastpath" from caffe2 operator protos created in Python down to C++. To facilitate this, we create helper template wrappers that pass a flag for "allow_broadcast_fastpath" down to elementwise functors. This flag will determine whether to try and take the broadcast fastpath, which we will add in subsequent diffs.

Test Plan: sandcastle + let github CI run

Differential Revision: D28154475

fbshipit-source-id: 15750a0bcd2994fbc6a61fb5653d8cae6b0177dd
2021-07-29 16:31:02 -07:00
Richard Barnes
ee44d73e59 Modernize override (#61744)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/61744

Test Plan: Sandcastle

Reviewed By: malfet

Differential Revision: D29717320

fbshipit-source-id: 6eea4295ee2e5572ab337620be412376fcc2f3cc
2021-07-23 23:04:46 -07:00
Nikita Shulga
a9b0a921d5 Disable avoid-non-const-global-variables lint check (#62008)
Summary:
As GoogleTest `TEST` macro is non-compliant with it as well as `DEFINE_DISPATCH`

All changes but the ones to `.clang-tidy` are generated using following script:
```
for i in `find . -type f -iname "*.c*" -or -iname "*.h"|xargs grep cppcoreguidelines-avoid-non-const-global-variables|cut -f1 -d:|sort|uniq`;  do sed -i "/\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)/d" $i; done
```

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

Reviewed By: driazati, r-barnes

Differential Revision: D29838584

Pulled By: malfet

fbshipit-source-id: 1b2f8602c945bd4ce50a9bfdd204755556e31d13
2021-07-22 18:04:40 -07:00
Hong Xu
7acb8b71e1 Remove AVX detection code that duplicates FindAVX.cmake (#61748)
Summary:
This PR deletes some code in `MiscCheck.cmake` that perform the exact
same functionality as `FindAVX.cmake`.

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

Reviewed By: ejguan

Differential Revision: D29791282

Pulled By: malfet

fbshipit-source-id: 6595fd1b61c8ae12b821fad8c9a34892dd52d213
2021-07-20 14:34:36 -07:00
Nikita Shulga
13a2025469 Delete empty caffe2/quantization/CMakeLists.txt (#59717)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/59717

Reviewed By: walterddr

Differential Revision: D28997598

Pulled By: malfet

fbshipit-source-id: ef2654577c0784254f3d74bc340cdabc76fa345c
2021-06-09 14:20:33 -07:00
Jongsoo Park
c436426be8 [fbgemm] fix gconv + acc16 (#59541)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/59541

Pull Request resolved: https://github.com/pytorch/FBGEMM/pull/621

Fixing 2 issues. These are actually 2 independent issues one in Caffe2 and another in FBGEMM, so no need to wait until FBGEMM is synchronized with PyTorch

1) conv 16-bit accumulation doesn't support fast gconv path, so TakeGConvFastPath_ should honor it
2) packed_index_ generates indices up to (G/GTogether_) F R S OC_per_G GTogether_ paddedICPerG which can exceed G kernel_prod OC_per_G paddedICPerG allocated in PackWeightMatrixForGConv (kernel_prod = F R S): e.g., when G=3, GTogether_=2, we allocate 3 F R S OC_per_G paddedICPerG but we access up to 2 F R S OC_per_G 2 paddedICPerG

BTW, not sure how we haven't known about this issue for so long. Any idea will be really appreciated.

Test Plan:
In a BDW machine,
buck test //caffe2/caffe2/quantization/server:conv_groupwise_dnnlowp_acc16_op_test -- --run-disabled

Reviewed By: dskhudia

Differential Revision: D28927214

fbshipit-source-id: 3ec98ea2fc177545392a0148daca592d80f40ad3
2021-06-07 19:20:59 -07:00
Jongsoo Park
dc55ab3f77 [fbgemm] fix bug handling bias in rowwise quantization of FC (#58022)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58022

Caffe2 Int8FC + rowwise quantization was not handling bias correctly.

Test Plan: The example in D28347336 doesn't show bigger error with rowwise quantization any more

Reviewed By: hx89, janeyx99

Differential Revision: D28347336

fbshipit-source-id: 3ac95fd2f29ef6e52705c3a2361b605813c2bcc5
2021-05-11 08:38:39 -07:00
Nikita Shulga
3a66a1cb99 [clang-tidy] Exclude cppcoreguidelines-avoid-magic-numbers (#57841)
Summary:
Add cppcoreguidelines-avoid-magic-numbers exclusion to clang-tidy
Remove existing nolint warnings using following script:
```
for file in `git ls-files | grep -v \.py`; do gsed '/^ *\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)/d' -i  $file; done
```

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

Reviewed By: samestep

Differential Revision: D28295045

Pulled By: malfet

fbshipit-source-id: 7c6e8d1213c9593f169ed3df6a916498f1a97163
2021-05-07 20:02:33 -07:00
Adolfo Victoria
2a178d34cd [Redo] Add pybind interface to caffe2 quantization server (#57378)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57378

Previous version got reverted due to some tests not running because I wasn't in the pytorch github org

Differential Revision: D28125562

fbshipit-source-id: 758c1c9a009e79febf6cbd062a47d2a3d94e3a78
2021-05-03 15:52:18 -07:00
Sam Estep
b9b768c0e7 Revert D28011862: Add pybind interface to caffe2 quantization server
Test Plan: revert-hammer

Differential Revision:
D28011862 (81ef82e5f4)

Original commit changeset: 647383017c4f

fbshipit-source-id: 1e2dbaba7c5fdc98d75a3bcf3722b529e9109348
2021-04-30 11:20:38 -07:00
Adolfo Victoria
81ef82e5f4 Add pybind interface to caffe2 quantization server (#57330)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/57330

Differential Revision: D28011862

fbshipit-source-id: 647383017c4fbc9afc4fd5aa5c771fd6a4619e29
2021-04-30 10:53:34 -07:00
Nikita Shulga
4cb534f92e Make PyTorch code-base clang-tidy compliant (#56892)
Summary:
This is an automatic change generated by the following script:
```
#!/usr/bin/env python3
from subprocess import check_output, check_call
import os

def get_compiled_files_list():
    import json
    with open("build/compile_commands.json") as f:
        data = json.load(f)
    files = [os.path.relpath(node['file']) for node in data]
    for idx, fname in enumerate(files):
        if fname.startswith('build/') and fname.endswith('.DEFAULT.cpp'):
            files[idx] = fname[len('build/'):-len('.DEFAULT.cpp')]
    return files

def run_clang_tidy(fname):
    check_call(["python3", "tools/clang_tidy.py", "-c", "build", "-x", fname,"-s"])
    changes = check_output(["git", "ls-files", "-m"])
    if len(changes) == 0:
        return
    check_call(["git", "commit","--all", "-m", f"NOLINT stubs for {fname}"])

def main():
    git_files = check_output(["git", "ls-files"]).decode("ascii").split("\n")
    compiled_files = get_compiled_files_list()
    for idx, fname in enumerate(git_files):
        if fname not in compiled_files:
            continue
        if fname.startswith("caffe2/contrib/aten/"):
            continue
        print(f"[{idx}/{len(git_files)}] Processing {fname}")
        run_clang_tidy(fname)

if __name__ == "__main__":
    main()
```

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

Reviewed By: H-Huang

Differential Revision: D27991944

Pulled By: malfet

fbshipit-source-id: 5415e1eb2c1b34319a4f03024bfaa087007d7179
2021-04-28 14:10:25 -07:00
frdong
92770d25cd fix comparison of narrow type with wide type in loop condition (#53951)
Summary:
fix Semmle warning: Comparison of narrow type with wide type in loop condition

For example there is below piece of code:
for (int i=0; i<array.size(); ++i) {}

The problem is that array.size() return type is size_t can be larger type than int depending on the implementation so there is chance that i overflows (for very large array that array size is beyond the range of integer) and this loop will never be terminated.

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

Reviewed By: zou3519

Differential Revision: D27181495

Pulled By: malfet

fbshipit-source-id: 0612c5cedcdc656c193085e7fbb87dd163f20688
2021-03-22 16:40:35 -07:00
Jongsoo Park
17f9b5ff4a [caffe2] increase deadline of test_dnnlowp_batch_matmul_int_constant_B (#54241)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54241

As title

Test Plan: buck test //caffe2/caffe2/quantization/server:batch_matmul_dnnlowp_op_test -- test_dnnlowp_batch_matmul_int_constant_B -[jongsoo@devbig279.ftw3 ~/server] buck test :batch_matmul_dnnlowp_op_test -- test_dnnlowp_batch_matmul_int_constant_B --run-disabled --stress-runs 10 --jobs 18

Reviewed By: dskhudia

Differential Revision: D27150098

fbshipit-source-id: be8bc1e57077a7399ae5fd5e5df14407b618a7f3
2021-03-22 13:13:22 -07:00
Chester Liu
f6df18f6ca Clean up future imports for Python 2 (#53349)
Summary:
See https://github.com/pytorch/pytorch/issues/42919

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

Reviewed By: malfet

Differential Revision: D27039089

Pulled By: bugra

fbshipit-source-id: 8063dc184248604506a8dbb1bcb73da8ec85bb18
2021-03-14 15:56:13 -07:00
Georgia Hong
3cc14a0dff [p2c2] Add support for Int8FCPackWeight in model transformation
Summary:
In order to enable FC int8 quantization in P2C2, we are trying to run the caffe2 op Int8FCPackWeight in the model transformation pipeline.

The net is being generated from the python side, and passed back into C++ and run here: https://fburl.com/diffusion/3zt1mp03,  with these dependencies included: https://fburl.com/diffusion/rdjtdtcf

However, when the net is executed, it errors out with:
```
Cannot create operator of type 'Int8FCPackWeight' on the device 'CPU'
```

This diff attempts to fix this issue.

Test Plan:
To reproduce, just this test without
```
buck test //aiplatform/modelstore/transformation/tests:pyper_to_caffe2_dispatcher_test
```

Reviewed By: jspark1105

Differential Revision: D25965167

fbshipit-source-id: a7414669abb8731177c14e8792de58f400970732
2021-01-26 16:35:23 -08:00
Richard Barnes
0be1a24b48 Drop unused imports from caffe2/quantization (#50493)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50493

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

From
```
./python/libcst/libcst codemod remove_unused_imports.RemoveUnusedImportsWithGlean --no-format caffe2/
```

Test Plan: Sandcastle Tests

Reviewed By: xush6528

Differential Revision: D25902417

fbshipit-source-id: aeebafce2c4fb649cdce5cf4fd4c5b3ee19923c0
2021-01-14 09:15:19 -08:00
Summer Deng
ec6de6a697 Clip small scales to fp16 min
Summary: When the FC output min max range is very small, we want to enforce a cutoff on the scale parameter to better generalize for future values that could fall beyond the original range.

Test Plan:
More analysis about the output distributions can be found in N425166

An example workflow using fp16 min clipping is f240972205

Reviewed By: jspark1105

Differential Revision: D25681249

fbshipit-source-id: c4dfbd3ee823886afed06e6c2eccfc29d612f7e6
2020-12-24 03:49:34 -08:00
Xiaohan Wei
9417e92722 op to gen quant params from min-max thresholds
Summary: Adding support to gen qparams to quantize a tensor from min and max thresholds of a tensor

Test Plan:
```
buck test mode/opt caffe2/caffe2/quantization/server:int8_gen_quant_params_min_max_test
```
```
Started reporting to test run: https://our.intern.facebook.com/intern/testinfra/testrun/5629499573509506
    ✓ ListingSuccess: caffe2/caffe2/quantization/server:int8_gen_quant_params_min_max_test - main (2.522)
    ✓ Pass: caffe2/caffe2/quantization/server:int8_gen_quant_params_min_max_test - test_int8_gen_quant_params_min_max_op (caffe2.caffe2.quantization.server.int8_gen_quant_params_min_max_test.TestInt8GenQuantParamsMinMaxOperator) (1.977)
Summary
  Pass: 1
  ListingSuccess: 1
```

Reviewed By: hx89

Differential Revision: D24485985

fbshipit-source-id: 18dee193f7895295d85d31dc013570e5d5d97357
2020-12-09 19:13:53 -08:00
Hector Yuen
b726a1bbf8 quantize bias of the quantization parameters (#48749)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/48749

this change reverts D25179863 (55e225a2dc) because in 1.0.0.14 this behavior got
reintroduced
we believe this was already working pre 1.0.0.9, then intel regressed which is
why we had to remove this quantization section, and in 1.0.0.14 they fixed it

Test Plan:
we tested ctr_instagram_5x which now passes with bitwise matching
hl475 will test the top6 models and if they match, we will use this point
to lock any further changes in the future

Reviewed By: venkatacrc

Differential Revision: D25283605

fbshipit-source-id: 33aa9af008c113d4d61e3461a44932b502bf42ea
2020-12-03 11:20:56 -08:00
Venkata Chintapalli
55e225a2dc Int8 FC fix to match NNPI ICE-REF step-C (#48459)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/48459

Bias should be kept it in FP32. There is no need to convert the bias to FP16.

Test Plan: https://internalfb.com/intern/testinfra/testrun/562950128141661

Reviewed By: hyuen

Differential Revision: D25179863

fbshipit-source-id: e25d948c613d2b2d5adf2b674fc2ea4b4c8d3920
2020-11-25 14:58:06 -08:00
Blaise Sanouillet
dd95bf65b6 [caffe2/FC DNNLOWP] Shrink Y_int32_ vector capacity when appropriate
Summary:
The FullyConnectedDNNLowPOp::Y_int32_ vectors consume between 1GB and 2GB on one of FB's larger applications. By adding tracing I noticed that the number of elements in each instance oscillates wildy over time. As the buffer backing a vector can only be extended in a resize operation, this means there is wasted memory space. So as a simple optimization, I added code to right-size the buffer backing the vector when the number of elements is less than half the vector capacity at that point; this doesn't affect the existing elements.

There is of course a memory/cpu tradeoff here - with the change we are doing more mallocs and frees. I added tracing to measure how many times we grow or shrink per second: it's about 100 per second on average, which is not a great deal.

Test Plan:
Memory growth impact: over 24 hours and after the startup period, the memory consumed by this code grows from 0.85GB to 1.20GB vs 0.95GB to 1.75GB in the baseline. [ source: https://fburl.com/scuba/heap_profiles/wm47kpfe ]
https://pxl.cl/1pHlJ

Reviewed By: jspark1105

Differential Revision: D24592098

fbshipit-source-id: 7892b35f24e42403653a74a1a9d06cbc7ee866b9
2020-10-29 11:19:45 -07:00
Daya Khudia
f47231bf0e [caffe2][dnnlowp] Remove openmp usage in quantize dnnlowp op
Summary: It creates cpu overload issues when openmp gets enabled and OMP_NUM_THREADS=1 is not set.

Test Plan: buck test //caffe2/caffe2/quantization/server:quantize_dnnlowp_op_test

Reviewed By: jspark1105

Differential Revision: D24437305

fbshipit-source-id: 426209fc33ce0d4680c478f584716837ee62cb5e
2020-10-20 19:33:56 -07:00
Jeff Hwang
ecf63351bc [mlf][efficiency] modify equalization scale operator to return single output (#46449)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/46449

modifies `ComputeEqualizationScale` to have a single output `S`

Test Plan:
```
buck test caffe2/caffe2/quantization/server:compute_equalization_scale_test
```

plus e2e tests

Reviewed By: hx89

Differential Revision: D23946768

fbshipit-source-id: 137c2d7a58bb858db411248606a5784b8066ab23
2020-10-16 01:22:37 -07:00