-
Notifications
You must be signed in to change notification settings - Fork 21.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update on "[GPU] Add an attribute to the torchscript model exported b…
…y metal" As title Differential Revision: [D24616430](https://our.internmc.facebook.com/intern/diff/D24616430/) [ghstack-poisoned]
- Loading branch information
Showing
92 changed files
with
1,721 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <ATen/ATen.h> | ||
#include <iostream> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
static void quantize_per_channel_4d_contiguous(benchmark::State& state) { | ||
const size_t batches = static_cast<size_t>(state.range(0)); | ||
const size_t channels = static_cast<size_t>(state.range(1)); | ||
const size_t height = static_cast<size_t>(state.range(2)); | ||
const size_t width = static_cast<size_t>(state.range(3)); | ||
|
||
at::Tensor a = at::rand({batches, channels, height, width}); | ||
at::Tensor scales = at::rand({channels}); | ||
at::Tensor zero_points = at::randint( | ||
0, 10, {channels}, at::TensorOptions().dtype(at::ScalarType::Int)); | ||
|
||
at::Tensor qa; | ||
for (auto _ : state) { | ||
qa = at::native::quantize_per_channel_cpu( | ||
a, scales, zero_points, 1, at::ScalarType::QUInt8); | ||
} | ||
} | ||
|
||
static void quantize_per_channel_4d_channels_last(benchmark::State& state) { | ||
const size_t batches = static_cast<size_t>(state.range(0)); | ||
const size_t channels = static_cast<size_t>(state.range(1)); | ||
const size_t height = static_cast<size_t>(state.range(2)); | ||
const size_t width = static_cast<size_t>(state.range(3)); | ||
|
||
at::Tensor a = at::rand( | ||
{batches, channels, height, width}, | ||
at::TensorOptions().memory_format(at::MemoryFormat::ChannelsLast)); | ||
at::Tensor scales = at::rand({channels}); | ||
at::Tensor zero_points = at::randint( | ||
0, 10, {channels}, at::TensorOptions().dtype(at::ScalarType::Int)); | ||
|
||
at::Tensor qa; | ||
for (auto _ : state) { | ||
qa = at::native::quantize_per_channel_cpu( | ||
a, scales, zero_points, 1, at::ScalarType::QUInt8); | ||
} | ||
} | ||
|
||
static void quantize_per_channel_2d(benchmark::State& state) { | ||
const size_t channels = static_cast<size_t>(state.range(0)); | ||
const size_t nelem = static_cast<size_t>(state.range(1)); | ||
|
||
at::Tensor a = at::rand({channels, nelem}); | ||
at::Tensor scales = at::rand({channels}); | ||
at::Tensor zero_points = at::randint( | ||
0, 10, {channels}, at::TensorOptions().dtype(at::ScalarType::Int)); | ||
|
||
at::Tensor qa; | ||
for (auto _ : state) { | ||
qa = at::native::quantize_per_channel_cpu( | ||
a, scales, zero_points, 0, at::ScalarType::QUInt8); | ||
} | ||
} | ||
|
||
static void GenerateSizes4d(benchmark::internal::Benchmark* b) { | ||
b->ArgNames({"N", "C", "H", "W"}); | ||
|
||
for (size_t n = 16; n < 256; n *= 2) { | ||
for (size_t c = 4; c < 256; c *= 2) { | ||
for (size_t hw = 4; hw < 256; hw *= 2) { | ||
b->Args({n, c, hw, hw}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
static void GenerateSizes2d(benchmark::internal::Benchmark* b) { | ||
b->ArgNames({"C", "N"}); | ||
|
||
for (size_t c = 4; c < 512; c *= 2) { | ||
for (size_t n = 4; n < 512; n *= 2) { | ||
b->Args({c, n}); | ||
} | ||
} | ||
} | ||
|
||
BENCHMARK(quantize_per_channel_2d)->Apply(GenerateSizes2d); | ||
BENCHMARK(quantize_per_channel_4d_contiguous)->Apply(GenerateSizes4d); | ||
BENCHMARK(quantize_per_channel_4d_channels_last)->Apply(GenerateSizes4d); | ||
BENCHMARK_MAIN(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.