Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +8 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/codegen/cuda/interface.h +52 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_conv_folding.h +22 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_graph_optimizations.h +20 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_linear_folding.h +12 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_linear_transpose.h +11 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_ops_to_mkldnn.h +13 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/fuse_linear.h +22 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/fuse_relu.h +9 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/graph_fuser.h +35 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/graph_rewrite_helper.h +50 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/guard_elimination.h +17 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/hoist_conv_packed_params.h +10 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inline_autodiff_subgraphs.h +13 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inline_fork_wait.h +14 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inline_forked_closures.h +10 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inliner.h +12 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inplace_check.h +9 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/insert_guards.h +19 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/integer_value_refinement.h +10 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lift_closures.h +10 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/liveness.h +22 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/loop_unrolling.h +34 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lower_grad_of.h +15 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lower_graph.h +20 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lower_tuples.h +18 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/metal_rewrite.h +15 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/mkldnn_rewrite.h +32 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/mobile_optimizer_type.h +13 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/normalize_ops.h +16 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/onednn_graph_fuser.h +61 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/onnx.h +28 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/pass_manager.h +134 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole.h +18 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_alias_sensitive.h +15 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_dict_idioms.h +36 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_list_idioms.h +70 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_non_tensor.h +12 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/prepack_folding.h +15 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/dedup_module_uses.h +26 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/finalize.h +61 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/fusion_passes.h +7 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/helper.h +214 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/insert_observers.h +66 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/insert_quant_dequant.h +44 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/quantization_patterns.h +1264 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/quantization_type.h +13 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/register_packed_params.h +18 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/refine_tuple_types.h +10 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/remove_dropout.h +12 -0
.gitattributes
CHANGED
|
@@ -4484,3 +4484,11 @@ tool_server/.venv/lib/python3.12/site-packages/torch/distributed/__pycache__/dis
|
|
| 4484 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/_flat_param.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4485 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/fully_sharded_data_parallel.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4486 |
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/symbolic_shapes.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4484 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/_flat_param.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4485 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/fully_sharded_data_parallel.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4486 |
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/symbolic_shapes.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4487 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/linalg/__pycache__/__init__.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4488 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/nested/_internal/__pycache__/ops.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4489 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/nn/__pycache__/functional.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4490 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/nn/modules/__pycache__/loss.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4491 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/nn/modules/__pycache__/module.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4492 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/nn/parallel/__pycache__/distributed.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4493 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/onnx/__pycache__/symbolic_opset9.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4494 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/sparse/__pycache__/_triton_ops_meta.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/codegen/cuda/interface.h
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/macros/Export.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
#include <torch/csrc/jit/passes/pass_manager.h>
|
| 6 |
+
#include <torch/csrc/jit/runtime/profiling_record.h>
|
| 7 |
+
|
| 8 |
+
/*
|
| 9 |
+
* This file contains APIs for cuda fuser;
|
| 10 |
+
*
|
| 11 |
+
* We use an empty static struct to hold the function pointers, which are
|
| 12 |
+
* registered separately. This is to support cpu-only compilation.
|
| 13 |
+
* Registration is done in torch/csrc/jit/codegen/cuda/register_interface.cpp
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
namespace torch::jit::fuser::cuda {
|
| 17 |
+
|
| 18 |
+
TORCH_API std::atomic<bool>& getCudaFusionGuardMode();
|
| 19 |
+
|
| 20 |
+
TORCH_API bool getSingletonFusion();
|
| 21 |
+
TORCH_API bool setSingletonFusion(bool value);
|
| 22 |
+
TORCH_API bool getHorizontalFusion();
|
| 23 |
+
TORCH_API bool setHorizontalFusion(bool value);
|
| 24 |
+
|
| 25 |
+
// dummy struct to allow API registration
|
| 26 |
+
struct CudaFuserInterface {
|
| 27 |
+
void (*fn_compile_n)(Node*) = nullptr;
|
| 28 |
+
void (*fn_run_n_s)(const Node*, Stack&) = nullptr;
|
| 29 |
+
void (*fn_fuse_graph)(std::shared_ptr<Graph>&) = nullptr;
|
| 30 |
+
bool (*fn_can_fuse_n)(const Node*) = nullptr;
|
| 31 |
+
void (*fn_insert_profile_inodes)(ProfilingRecord* pr) = nullptr;
|
| 32 |
+
bool (*fn_profile_n)(const Node*) = nullptr;
|
| 33 |
+
bool (*fn_skip_n)(const std::string&, bool flip) = nullptr;
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
// Get interface, this is used by registration and user facing API internally
|
| 37 |
+
TORCH_API CudaFuserInterface* getFuserInterface();
|
| 38 |
+
|
| 39 |
+
TORCH_API void compileFusionGroup(Node* fusion_node);
|
| 40 |
+
TORCH_API void runFusionGroup(const Node* fusion_node, Stack& stack);
|
| 41 |
+
TORCH_API void fuseGraph(std::shared_ptr<Graph>&);
|
| 42 |
+
TORCH_API bool canFuseNode(const Node* node);
|
| 43 |
+
TORCH_API void InsertProfileNodesForCUDAFuser(ProfilingRecord* pr);
|
| 44 |
+
TORCH_API bool profileNode(const Node* node);
|
| 45 |
+
|
| 46 |
+
TORCH_API bool skipNode(const std::string& symbol_str, bool flip = true);
|
| 47 |
+
|
| 48 |
+
TORCH_API bool isEnabled();
|
| 49 |
+
TORCH_API bool setEnabled(bool is_enabled);
|
| 50 |
+
TORCH_API bool canBeEnabled();
|
| 51 |
+
|
| 52 |
+
} // namespace torch::jit::fuser::cuda
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_conv_folding.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Fuses Convolution -> Batchnorm into a single Convolution by
|
| 8 |
+
// folding batchnorm weights into conv weights.
|
| 9 |
+
// This pass only works on Frozen Graphs; otherwise it is a No-Op.
|
| 10 |
+
TORCH_API bool FoldFrozenConvBatchnorm(std::shared_ptr<Graph>& graph);
|
| 11 |
+
|
| 12 |
+
// Fuses Convolution -> Add/Sub into a single Convolution by
|
| 13 |
+
// folding add constant tensor into conv weights.
|
| 14 |
+
// This pass only works on Frozen Graphs; otherwise it is a No-Op.
|
| 15 |
+
TORCH_API bool FoldFrozenConvAddOrSub(std::shared_ptr<Graph>& graph);
|
| 16 |
+
|
| 17 |
+
// Fuses Convolution -> Mul/Div into a single Convolution by
|
| 18 |
+
// folding add constant tensor into conv weights.
|
| 19 |
+
// This pass only works on Frozen Graphs; otherwise it is a No-Op.
|
| 20 |
+
TORCH_API bool FoldFrozenConvMulOrDiv(std::shared_ptr<Graph>& graph);
|
| 21 |
+
|
| 22 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_graph_optimizations.h
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
/** \brief Runs a set of Optimizations that Optimize Frozen Graphs
|
| 6 |
+
*
|
| 7 |
+
* Currently this set of optimizations is:
|
| 8 |
+
* - FoldFrozenConvBatchnorm
|
| 9 |
+
* - FoldFrozenConvAddOrSub
|
| 10 |
+
* - FoldFrozenConvMulOrDiv
|
| 11 |
+
* - FoldFrozenLinearBatchnorm
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
namespace torch::jit {
|
| 15 |
+
|
| 16 |
+
TORCH_API void OptimizeFrozenGraph(
|
| 17 |
+
std::shared_ptr<Graph>& graph,
|
| 18 |
+
bool optimize_numerics = true);
|
| 19 |
+
|
| 20 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_linear_folding.h
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Fuses Linear -> BatchNormNd into a single Linear by
|
| 8 |
+
// folding batchnorm weights into linear weights.
|
| 9 |
+
// This pass only works on Frozen Graphs; otherwise it is a No-Op.
|
| 10 |
+
TORCH_API bool FoldFrozenLinearBatchnorm(std::shared_ptr<Graph>& graph);
|
| 11 |
+
|
| 12 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_linear_transpose.h
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Transposes the weight matrix for frozen linear modules.
|
| 8 |
+
// and converts it into a matmul
|
| 9 |
+
TORCH_API bool FrozenLinearTranspose(std::shared_ptr<Graph>& graph);
|
| 10 |
+
|
| 11 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/frozen_ops_to_mkldnn.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Converts operators & their parameters to mkldnn if it is profitable
|
| 8 |
+
// Currently encompassing Conv2d and Conv3d, and Linear
|
| 9 |
+
// Op must be in float32 and mkldnn must be built
|
| 10 |
+
// This pass only works on frozen graph
|
| 11 |
+
TORCH_API void ConvertFrozenOpsToMKLDNN(std::shared_ptr<Graph>& graph);
|
| 12 |
+
|
| 13 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/fuse_linear.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** \brief Fusing linear patterns as single at::linear for easier pattern
|
| 2 |
+
* matching in later passes
|
| 3 |
+
*/
|
| 4 |
+
#pragma once
|
| 5 |
+
|
| 6 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 7 |
+
|
| 8 |
+
namespace torch::jit {
|
| 9 |
+
|
| 10 |
+
/** \brief Match the at::linear pattern and fuse it into a single at::linear
|
| 11 |
+
* This pass fuse the addmm or matmul + add generated by JIT back to linear
|
| 12 |
+
* This pass can be deleted once the JIT can emit the aten::linear in the future
|
| 13 |
+
*/
|
| 14 |
+
TORCH_API void FuseLinear(std::shared_ptr<Graph>& graph);
|
| 15 |
+
|
| 16 |
+
/** Swap functional linear CallFunctions to aten::linear
|
| 17 |
+
*/
|
| 18 |
+
TORCH_API void SwapFunctionalLinear(std::shared_ptr<Graph>& graph);
|
| 19 |
+
/** Swap all functional linear CallFunctions in module
|
| 20 |
+
*/
|
| 21 |
+
TORCH_API void SwapFunctionalLinear(Module& module);
|
| 22 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/fuse_relu.h
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::jit {
|
| 7 |
+
TORCH_API void FuseAddRelu(script::Module& module);
|
| 8 |
+
TORCH_API void FuseAddRelu(std::shared_ptr<Graph>& graph);
|
| 9 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/graph_fuser.h
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
TORCH_API bool canFuseOnCPULegacy();
|
| 8 |
+
TORCH_API void overrideCanFuseOnCPULegacy(bool value);
|
| 9 |
+
|
| 10 |
+
// NB: Be sure to run DCE before fusion, because dead instructions
|
| 11 |
+
// can prevent fusion opportunities from being exploited.
|
| 12 |
+
// On Windows will noop, NYI
|
| 13 |
+
TORCH_API void FuseGraph(
|
| 14 |
+
std::shared_ptr<Graph>& graph,
|
| 15 |
+
bool strict_fuser_check = false);
|
| 16 |
+
|
| 17 |
+
// \brief Custom fusion pass using a node-level callback to
|
| 18 |
+
// determine the inclusion of nodes in a subgraph.
|
| 19 |
+
//
|
| 20 |
+
// This helper omits aliased inputs and fusion across control flow
|
| 21 |
+
// boundaries.
|
| 22 |
+
//
|
| 23 |
+
// \arg graph The graph to be modified in-place
|
| 24 |
+
// \arg is_fusable A callback run on each fusable node in the graph.
|
| 25 |
+
// \arg kind The label given to the resultant fused subgraph
|
| 26 |
+
// \arg arg_limit The maximum number of args the resultant fused subgraph
|
| 27 |
+
// should have. Note: This will likely develop into a general
|
| 28 |
+
// post condition on the fused subgraph.
|
| 29 |
+
TORCH_API void CustomFuseGraph(
|
| 30 |
+
std::shared_ptr<Graph>& graph,
|
| 31 |
+
const std::function<bool(Node*)>& is_fusable,
|
| 32 |
+
Symbol kind,
|
| 33 |
+
size_t arg_limit = std::numeric_limits<size_t>::max());
|
| 34 |
+
|
| 35 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/graph_rewrite_helper.h
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/irparser.h>
|
| 5 |
+
#include <torch/csrc/jit/ir/subgraph_matcher.h>
|
| 6 |
+
#include <torch/csrc/jit/passes/subgraph_rewrite.h>
|
| 7 |
+
|
| 8 |
+
namespace torch::jit::graph_rewrite_helper {
|
| 9 |
+
|
| 10 |
+
std::string getFuncName(Value* func_value);
|
| 11 |
+
Value* getValue(
|
| 12 |
+
const std::string& name,
|
| 13 |
+
const std::unordered_map<const Value*, Value*>& match_vmap,
|
| 14 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 15 |
+
std::optional<IValue> getIValue(
|
| 16 |
+
const std::string& name,
|
| 17 |
+
const std::unordered_map<const Value*, Value*>& match_vmap,
|
| 18 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 19 |
+
TORCH_API void replaceConvolutionWithAtenConv(std::shared_ptr<Graph>& graph);
|
| 20 |
+
|
| 21 |
+
bool isClampFusable(
|
| 22 |
+
const Match& match,
|
| 23 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 24 |
+
|
| 25 |
+
// This struct contains a compiled IR patterns slated for use in the
|
| 26 |
+
// findPatternMatches function. The struct encapsulates the common
|
| 27 |
+
// information from parseIR that is used in conjunction with the
|
| 28 |
+
// pattern matching facility. A const instance of this struct can
|
| 29 |
+
// also be stored away to cache the compiled IR pattern and reduce
|
| 30 |
+
// runtime cost
|
| 31 |
+
struct PatternInfo {
|
| 32 |
+
std::string pattern_string;
|
| 33 |
+
std::unique_ptr<Graph> pattern_graph;
|
| 34 |
+
std::unordered_map<std::string, Value*> vmap;
|
| 35 |
+
std::vector<MatchFilter> filters;
|
| 36 |
+
|
| 37 |
+
static PatternInfo parse_from_str(
|
| 38 |
+
std::string pattern_string,
|
| 39 |
+
const std::vector<MatchFilter>& filters = {}) {
|
| 40 |
+
PatternInfo rv{
|
| 41 |
+
std::move(pattern_string),
|
| 42 |
+
std::make_unique<Graph>(),
|
| 43 |
+
decltype(vmap){},
|
| 44 |
+
filters};
|
| 45 |
+
parseIR(rv.pattern_string, rv.pattern_graph.get(), rv.vmap);
|
| 46 |
+
return rv;
|
| 47 |
+
}
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
} // namespace torch::jit::graph_rewrite_helper
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/guard_elimination.h
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/ATen.h>
|
| 4 |
+
#include <ATen/core/ivalue.h>
|
| 5 |
+
#include <ATen/core/jit_type.h>
|
| 6 |
+
#include <ATen/core/stack.h>
|
| 7 |
+
#include <torch/csrc/Export.h>
|
| 8 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 9 |
+
|
| 10 |
+
#include <list>
|
| 11 |
+
#include <vector>
|
| 12 |
+
|
| 13 |
+
namespace torch::jit {
|
| 14 |
+
|
| 15 |
+
TORCH_API void EliminateRedundantGuards(std::shared_ptr<Graph> graph);
|
| 16 |
+
|
| 17 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/hoist_conv_packed_params.h
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::jit {
|
| 7 |
+
|
| 8 |
+
void HoistConvPackedParams(script::Module& m);
|
| 9 |
+
|
| 10 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inline_autodiff_subgraphs.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
TORCH_API bool canRunWithAutograd(Node* node);
|
| 8 |
+
|
| 9 |
+
TORCH_API void InlineAutodiffSubgraphs(
|
| 10 |
+
std::shared_ptr<Graph>& graph,
|
| 11 |
+
size_t threshold = 5);
|
| 12 |
+
|
| 13 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inline_fork_wait.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Inline Fork and Wait calls. This is used, for example, in ONNX export, where
|
| 8 |
+
// we do not support the explicit parallelism structures and would rather
|
| 9 |
+
// just have a flat graph. This inlines the forked section in the fork()
|
| 10 |
+
// callsite and replaces uses of the result of wait() calls with the values
|
| 11 |
+
// produced from the (now-inlined) forked section.
|
| 12 |
+
TORCH_API void InlineForkWait(const std::shared_ptr<Graph>& graph);
|
| 13 |
+
|
| 14 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inline_forked_closures.h
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/Export.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::jit {
|
| 7 |
+
|
| 8 |
+
TORCH_API void inlineForkedClosures(std::shared_ptr<Graph>& to_clean);
|
| 9 |
+
|
| 10 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inliner.h
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Inline function and method calls.
|
| 8 |
+
TORCH_API void Inline(Graph& graph);
|
| 9 |
+
|
| 10 |
+
TORCH_API GraphFunction* tryToGraphFunction(Node* n);
|
| 11 |
+
|
| 12 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/inplace_check.h
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
TORCH_API void CheckInplace(std::shared_ptr<Graph>& graph);
|
| 8 |
+
|
| 9 |
+
}
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/insert_guards.h
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/ATen.h>
|
| 4 |
+
#include <ATen/core/ivalue.h>
|
| 5 |
+
#include <ATen/core/jit_type.h>
|
| 6 |
+
#include <ATen/core/stack.h>
|
| 7 |
+
#include <torch/csrc/Export.h>
|
| 8 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 9 |
+
|
| 10 |
+
#include <list>
|
| 11 |
+
#include <vector>
|
| 12 |
+
|
| 13 |
+
namespace torch::jit {
|
| 14 |
+
|
| 15 |
+
TORCH_API void InsertGuards(std::shared_ptr<Graph> graph);
|
| 16 |
+
|
| 17 |
+
TORCH_API void RemoveProfilingNodes(const std::shared_ptr<Graph>& graph);
|
| 18 |
+
|
| 19 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/integer_value_refinement.h
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// return true if graph is modified
|
| 8 |
+
TORCH_API bool RefineIntegerValues(const std::shared_ptr<Graph>& graph);
|
| 9 |
+
|
| 10 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lift_closures.h
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/Export.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::jit {
|
| 7 |
+
|
| 8 |
+
TORCH_API void liftClosures(const std::shared_ptr<Graph>& graph);
|
| 9 |
+
|
| 10 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/liveness.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/ATen.h>
|
| 4 |
+
#include <ATen/core/ivalue.h>
|
| 5 |
+
#include <ATen/core/jit_type.h>
|
| 6 |
+
#include <ATen/core/stack.h>
|
| 7 |
+
#include <c10/util/sparse_bitset.h>
|
| 8 |
+
#include <torch/csrc/Export.h>
|
| 9 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 10 |
+
#include <list>
|
| 11 |
+
#include <unordered_map>
|
| 12 |
+
#include <vector>
|
| 13 |
+
|
| 14 |
+
namespace torch::jit {
|
| 15 |
+
|
| 16 |
+
using SparseBitVector = ::c10::SparseBitVector<256>;
|
| 17 |
+
|
| 18 |
+
// BuildLivenessSets computes "bailout" liveness which is equivalent to
|
| 19 |
+
// "{LIVE_IN} or {GEN}" or "{LIVE_OUT} - {KILL}"
|
| 20 |
+
TORCH_API std::unordered_map<Node*, std::vector<Value*>> BuildLivenessSets(
|
| 21 |
+
std::shared_ptr<Graph> graph);
|
| 22 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/loop_unrolling.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// return true if graph is modified
|
| 8 |
+
TORCH_API bool UnrollLoops(std::shared_ptr<Graph>& graph);
|
| 9 |
+
|
| 10 |
+
// Only unrolls constant loops. Will unroll them regardless of loop block size
|
| 11 |
+
TORCH_API bool UnrollConstantLoops(std::shared_ptr<Graph>& graph);
|
| 12 |
+
|
| 13 |
+
TORCH_API Node* PeelLoop(Node* n, size_t times);
|
| 14 |
+
|
| 15 |
+
// return true if graph is modified
|
| 16 |
+
TORCH_API bool PeelProfilingLoops(const std::shared_ptr<Graph>& graph);
|
| 17 |
+
|
| 18 |
+
struct TORCH_API LoopsPeeler {
|
| 19 |
+
LoopsPeeler(std::function<bool(Node* n)> callback, size_t num_iterations = 1)
|
| 20 |
+
: callback_(std::move(callback)), num_iterations_(num_iterations) {}
|
| 21 |
+
|
| 22 |
+
bool run(const std::shared_ptr<Graph>& graph);
|
| 23 |
+
|
| 24 |
+
private:
|
| 25 |
+
void collectLoop(Node* n);
|
| 26 |
+
void collectLoops(Block* block);
|
| 27 |
+
void peelLoops();
|
| 28 |
+
|
| 29 |
+
std::function<bool(Node* n)> callback_ = nullptr;
|
| 30 |
+
Node* in_loop_ = nullptr;
|
| 31 |
+
std::list<Node*> loops_to_peel_;
|
| 32 |
+
size_t num_iterations_ = 1;
|
| 33 |
+
};
|
| 34 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lower_grad_of.h
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// This pass removes 'grad_of' nodes, replacing them with conditionals of
|
| 8 |
+
// the form:
|
| 9 |
+
// if any_defined(inputs):
|
| 10 |
+
// outputs = <original_computation>
|
| 11 |
+
// else:
|
| 12 |
+
// outputs = undefineds
|
| 13 |
+
TORCH_API void LowerGradOf(Graph& g);
|
| 14 |
+
|
| 15 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lower_graph.h
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
using ModulePtr = c10::intrusive_ptr<c10::ivalue::Object>;
|
| 8 |
+
|
| 9 |
+
// Given a graph with of a method which first argument is %self, lower it to a
|
| 10 |
+
// graph where all attributes accesses are replaced with explicit inputs of the
|
| 11 |
+
// graph (rather than results of prim::GetAttr executed on %self).
|
| 12 |
+
//
|
| 13 |
+
// Returns a tuple (graph, parameters) where the last module.parameters.size()
|
| 14 |
+
// inputs to the graph are the trainable parameters used in this method. The
|
| 15 |
+
// remaining inputs are the true inputs to the function.
|
| 16 |
+
TORCH_API std::pair<std::shared_ptr<Graph>, std::vector<IValue>> LowerGraph(
|
| 17 |
+
Graph& graph,
|
| 18 |
+
const ModulePtr& self);
|
| 19 |
+
|
| 20 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/lower_tuples.h
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// removes tuples where TupleConstruct and TupleUnpack are matched
|
| 8 |
+
// but leaves tuples in place across if statements, loops, and as inputs/outputs
|
| 9 |
+
TORCH_API void LowerSimpleTuples(const std::shared_ptr<Graph>& graph);
|
| 10 |
+
|
| 11 |
+
// removes _all_ tuples and raises an error if some cannot be removed
|
| 12 |
+
// this is used by ONNX to ensure there are not tuples before conversion,
|
| 13 |
+
// but will not work on graphs whose inputs contain tuples.
|
| 14 |
+
TORCH_API void LowerAllTuples(const std::shared_ptr<Graph>& graph);
|
| 15 |
+
|
| 16 |
+
TORCH_API void LowerSimpleTuples(Block* block);
|
| 17 |
+
|
| 18 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/metal_rewrite.h
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <torch/csrc/jit/api/module.h>
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
#include <string>
|
| 5 |
+
#include <vector>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit {
|
| 8 |
+
TORCH_API void metalInsertPrePackedOps(std::shared_ptr<Graph>& graph);
|
| 9 |
+
TORCH_API void metalInsertPrePackedOps(script::Module& module);
|
| 10 |
+
TORCH_API void metalFusePrePackedConvWithClamp(script::Module& module);
|
| 11 |
+
TORCH_API void metalFoldPrePackingOps(script::Module& module);
|
| 12 |
+
TORCH_API script::Module metalOptimizeForMobile(
|
| 13 |
+
const script::Module& module,
|
| 14 |
+
const std::vector<std::string>& preserved_methods);
|
| 15 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/mkldnn_rewrite.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/Config.h>
|
| 4 |
+
#include <torch/csrc/jit/api/module.h>
|
| 5 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 6 |
+
#include <torch/csrc/jit/passes/subgraph_rewrite.h>
|
| 7 |
+
|
| 8 |
+
#if AT_MKLDNN_ENABLED()
|
| 9 |
+
|
| 10 |
+
#include <ideep/tensor.hpp>
|
| 11 |
+
|
| 12 |
+
#endif // AT_MKLDNN_ENABLED()
|
| 13 |
+
|
| 14 |
+
namespace torch::jit {
|
| 15 |
+
|
| 16 |
+
#if AT_MKLDNN_ENABLED()
|
| 17 |
+
|
| 18 |
+
namespace mkldnn {
|
| 19 |
+
|
| 20 |
+
const static std::map<std::string, std::vector<torch::jit::MatchFilter>>
|
| 21 |
+
fusion_rewrite_map = {
|
| 22 |
+
{"none", {}},
|
| 23 |
+
{"relu", {}},
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
} // namespace mkldnn
|
| 27 |
+
|
| 28 |
+
#endif // AT_MKLDNN_ENABLED()
|
| 29 |
+
|
| 30 |
+
void FuseConvWithEltwise(std::shared_ptr<Graph>& graph);
|
| 31 |
+
|
| 32 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/mobile_optimizer_type.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <cstdint>
|
| 4 |
+
|
| 5 |
+
enum class MobileOptimizerType : int8_t {
|
| 6 |
+
CONV_BN_FUSION,
|
| 7 |
+
INSERT_FOLD_PREPACK_OPS,
|
| 8 |
+
REMOVE_DROPOUT,
|
| 9 |
+
FUSE_ADD_RELU,
|
| 10 |
+
HOIST_CONV_PACKED_PARAMS,
|
| 11 |
+
CONV_1D_TO_2D,
|
| 12 |
+
VULKAN_AUTOMATIC_GPU_TRANSFER,
|
| 13 |
+
};
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/normalize_ops.h
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// This pass converts aten ops to a normalized form. It is
|
| 8 |
+
// run immediately after IR generation in both the tracer and compiler,
|
| 9 |
+
// so downstream consumers of the IR do not need handle ops in their
|
| 10 |
+
// pre-normalized form.
|
| 11 |
+
// Currently only handles normalization of op aliases.
|
| 12 |
+
TORCH_API void NormalizeOps(const std::shared_ptr<Graph>& graph);
|
| 13 |
+
|
| 14 |
+
const std::unordered_map<Symbol, Symbol>& getOperatorAliasMap();
|
| 15 |
+
|
| 16 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/onednn_graph_fuser.h
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
#include <torch/csrc/jit/passes/pass_manager.h>
|
| 5 |
+
|
| 6 |
+
#include <ATen/Config.h>
|
| 7 |
+
|
| 8 |
+
namespace torch::jit {
|
| 9 |
+
|
| 10 |
+
namespace fuser::onednn {
|
| 11 |
+
|
| 12 |
+
static std::atomic<bool> onednn_enabled{true};
|
| 13 |
+
|
| 14 |
+
static std::atomic<bool>& getLlgaEnabled() {
|
| 15 |
+
return onednn_enabled;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
TORCH_API void fuseGraph(std::shared_ptr<Graph>& g);
|
| 19 |
+
|
| 20 |
+
} // namespace fuser::onednn
|
| 21 |
+
|
| 22 |
+
struct C10_EXPORT RegisterLlgaFuseGraph
|
| 23 |
+
: public PassManager<RegisterLlgaFuseGraph> {
|
| 24 |
+
static bool setEnabled(bool enabled) {
|
| 25 |
+
TORCH_CHECK(
|
| 26 |
+
AT_MKLDNN_ENABLED(),
|
| 27 |
+
"Running oneDNN Graph fuser is only supported with MKLDNN builds.");
|
| 28 |
+
bool oldState = fuser::onednn::getLlgaEnabled();
|
| 29 |
+
fuser::onednn::getLlgaEnabled() = enabled;
|
| 30 |
+
if (enabled) {
|
| 31 |
+
registerPass(fuser::onednn::fuseGraph);
|
| 32 |
+
} else {
|
| 33 |
+
clearPass();
|
| 34 |
+
}
|
| 35 |
+
return oldState;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
static bool isEnabled() {
|
| 39 |
+
return fuser::onednn::getLlgaEnabled();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// override PassManager::registerPass to register pre-pass
|
| 43 |
+
static bool registerPass(GraphPass p) {
|
| 44 |
+
if (!isRegistered()) {
|
| 45 |
+
passID(registerPrePass(std::move(p)), true);
|
| 46 |
+
isRegistered(true);
|
| 47 |
+
return false;
|
| 48 |
+
}
|
| 49 |
+
return true;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// override PassManager::clearPass to clear pre-pass
|
| 53 |
+
static void clearPass() {
|
| 54 |
+
if (isRegistered()) {
|
| 55 |
+
clearPrePass(passID());
|
| 56 |
+
isRegistered(true);
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/onnx.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
#include <torch/csrc/onnx/onnx.h>
|
| 5 |
+
#include <torch/csrc/utils/pybind.h>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit {
|
| 8 |
+
|
| 9 |
+
TORCH_API std::shared_ptr<Graph> ToONNX(
|
| 10 |
+
std::shared_ptr<Graph>& state,
|
| 11 |
+
::torch::onnx::OperatorExportTypes operator_export_type);
|
| 12 |
+
TORCH_API py::dict BlockToONNX(
|
| 13 |
+
Block* old_block,
|
| 14 |
+
Block* new_block,
|
| 15 |
+
::torch::onnx::OperatorExportTypes operator_export_type,
|
| 16 |
+
py::dict& env,
|
| 17 |
+
py::set& values_in_env,
|
| 18 |
+
bool is_sub_block = false);
|
| 19 |
+
TORCH_API void NodeToONNX(
|
| 20 |
+
Node* old_node,
|
| 21 |
+
Block* new_block,
|
| 22 |
+
::torch::onnx::OperatorExportTypes operator_export_type,
|
| 23 |
+
py::dict& env,
|
| 24 |
+
py::set& values_in_env);
|
| 25 |
+
TORCH_API void RemovePrintOps(std::shared_ptr<Graph>& graph);
|
| 26 |
+
TORCH_API void PreprocessCaffe2Ops(std::shared_ptr<Graph>& graph);
|
| 27 |
+
|
| 28 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/pass_manager.h
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
/* `getCustomPrePasses()` returns a vector of passes that will be executed
|
| 6 |
+
* after differentiation but before any fusion. This is the de-facto location
|
| 7 |
+
* for compiler backends to insert passes.
|
| 8 |
+
*
|
| 9 |
+
* `getCustomPostPasses()` returns a vector of passes that will be
|
| 10 |
+
* executed after differentiation and after fusion (if any). This is the
|
| 11 |
+
* location for fusion cleanup passes if they are needed.
|
| 12 |
+
*
|
| 13 |
+
* Static registration of a pass can be done by creating a global
|
| 14 |
+
* `Register{Pre,Post}Pass r(Pass)` variable in a compilation unit.
|
| 15 |
+
*
|
| 16 |
+
* pass_manager.h uses a Meyer's singleton to store a vector of `Pass`es, which
|
| 17 |
+
* modify the IR graph in place.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
namespace torch::jit {
|
| 21 |
+
|
| 22 |
+
// A pass modifies a Graph in place.
|
| 23 |
+
using GraphPass = std::function<void(std::shared_ptr<Graph>&)>;
|
| 24 |
+
|
| 25 |
+
// Since Passes are std::functions, we associate a UUID to each pass, this way
|
| 26 |
+
// if we want to deregister a pass, we have something to reference it by.
|
| 27 |
+
using GraphPassNameType = unsigned int;
|
| 28 |
+
|
| 29 |
+
// Graph pass entries have a name associated with them
|
| 30 |
+
using GraphPassEntry = std::pair<GraphPass, GraphPassNameType>;
|
| 31 |
+
|
| 32 |
+
// Return currently registered passes. Passes are stored in a static vector
|
| 33 |
+
TORCH_API std::vector<std::pair<GraphPass, GraphPassNameType>>&
|
| 34 |
+
getCustomPostPasses();
|
| 35 |
+
TORCH_API std::vector<std::pair<GraphPass, GraphPassNameType>>&
|
| 36 |
+
getCustomPrePasses();
|
| 37 |
+
|
| 38 |
+
TORCH_API GraphPassNameType registerPostPass(GraphPass p);
|
| 39 |
+
TORCH_API GraphPassNameType registerPrePass(GraphPass p);
|
| 40 |
+
|
| 41 |
+
// Look up pass by name passed in, remove it from registered passes
|
| 42 |
+
TORCH_API void clearPostPass(GraphPassNameType p);
|
| 43 |
+
TORCH_API void clearPrePass(GraphPassNameType p);
|
| 44 |
+
|
| 45 |
+
// Remove all passes
|
| 46 |
+
TORCH_API void clearAllPostPasses();
|
| 47 |
+
TORCH_API void clearAllPrePasses();
|
| 48 |
+
|
| 49 |
+
// LEGACY CALL
|
| 50 |
+
struct TORCH_API RegisterPostPass {
|
| 51 |
+
RegisterPostPass(GraphPass p);
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
using RegisterPass = RegisterPostPass;
|
| 55 |
+
|
| 56 |
+
/*
|
| 57 |
+
* PassManager is a wrapper on the register/clear PostPass functions above. It
|
| 58 |
+
* will register the pass provided in "registerPass" and will hold on to its
|
| 59 |
+
* associated name that way clearPass can be later called and will delete the
|
| 60 |
+
* pass used to register when called.
|
| 61 |
+
*
|
| 62 |
+
* PassManager is templated because we want static variables based on a
|
| 63 |
+
* particular GraphPass. When deriving from PassManager, you should send as the
|
| 64 |
+
* template parameter your derived class as you would for the curiously
|
| 65 |
+
* recurring template pattern. This template parameter isn't actually used and
|
| 66 |
+
* is simply done to prevent static members from being shared across derived
|
| 67 |
+
* types.
|
| 68 |
+
*/
|
| 69 |
+
template <typename DerivedType>
|
| 70 |
+
struct C10_EXPORT PassManager {
|
| 71 |
+
private:
|
| 72 |
+
// We want this class to be abstract because it's
|
| 73 |
+
virtual void abstract() = 0;
|
| 74 |
+
|
| 75 |
+
protected:
|
| 76 |
+
/*
|
| 77 |
+
* isRegistered() will return if a pass has been registered
|
| 78 |
+
* isRegistered(true) will change the value of the internal static bool
|
| 79 |
+
*
|
| 80 |
+
* There's an internal static bool to this function to keep track of the
|
| 81 |
+
* state, this is so when functions are derived from this class, they don't
|
| 82 |
+
* have to worry about initializing the static members.
|
| 83 |
+
*/
|
| 84 |
+
static bool isRegistered(bool flip_bit = false) {
|
| 85 |
+
static bool val = false;
|
| 86 |
+
if (flip_bit)
|
| 87 |
+
val = !val;
|
| 88 |
+
return val;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/*
|
| 92 |
+
* name() will return the name of the registered pass
|
| 93 |
+
* name(pass_name, true) will set the name of the pass
|
| 94 |
+
* Similarly to isRegistered we use an internal static variable to hold the
|
| 95 |
+
* name.
|
| 96 |
+
*/
|
| 97 |
+
static GraphPassNameType passID(
|
| 98 |
+
GraphPassNameType PassID = 0,
|
| 99 |
+
bool set = false) {
|
| 100 |
+
static GraphPassNameType pass_id = 0;
|
| 101 |
+
if (set)
|
| 102 |
+
pass_id = PassID;
|
| 103 |
+
return pass_id;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
public:
|
| 107 |
+
// registerPass(pass) will register the pass provided and set the
|
| 108 |
+
// name/isRegistered functions appropriately, it returns a bool value
|
| 109 |
+
// indicating whether the given pass is already registered previously.
|
| 110 |
+
static bool registerPass(GraphPass p) {
|
| 111 |
+
if (!isRegistered()) {
|
| 112 |
+
// If we don't already have a registered pass, register pass
|
| 113 |
+
// hold on to its name, change isRegistered to true
|
| 114 |
+
passID(registerPostPass(std::move(p)), true);
|
| 115 |
+
isRegistered(true);
|
| 116 |
+
return false;
|
| 117 |
+
}
|
| 118 |
+
return true;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// Calls ClearPostPass(passID())
|
| 122 |
+
static void clearPass() {
|
| 123 |
+
// If the pass is registered, clear it and change isRegistered to false.
|
| 124 |
+
if (isRegistered()) {
|
| 125 |
+
clearPostPass(passID());
|
| 126 |
+
isRegistered(true);
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// clang-tidy requires virtual destructor;
|
| 131 |
+
virtual ~PassManager() = default;
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole.h
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// return true if graph is modified
|
| 8 |
+
TORCH_API bool PeepholeOptimize(
|
| 9 |
+
const std::shared_ptr<Graph>& graph,
|
| 10 |
+
bool disable_shape_peepholes = false);
|
| 11 |
+
// return true if graph is modified
|
| 12 |
+
TORCH_API bool PeepholeOptimize(
|
| 13 |
+
Block* block,
|
| 14 |
+
bool disable_shape_peepholes = false);
|
| 15 |
+
// return true if graph is modified
|
| 16 |
+
TORCH_API bool FuseAddMM(const std::shared_ptr<Graph>& graph);
|
| 17 |
+
|
| 18 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_alias_sensitive.h
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Peephole Optimizes alias sensitive peepholes
|
| 8 |
+
// Currently this is invoked as part of PeepholeOptimize
|
| 9 |
+
// return true if graph is modified
|
| 10 |
+
// Optimizes on TensorType if shape_peepholes is true
|
| 11 |
+
TORCH_API bool PeepholeOptimizeAliasSensitive(
|
| 12 |
+
const std::shared_ptr<Graph>& graph,
|
| 13 |
+
bool shape_peepholes);
|
| 14 |
+
|
| 15 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_dict_idioms.h
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Peephole Optimizes Dict Ops such as len() and __getitem__
|
| 8 |
+
// 1. getitem optimizations
|
| 9 |
+
// Given a function like this:
|
| 10 |
+
// def foo():
|
| 11 |
+
// d = {0 : 1}
|
| 12 |
+
// x = d[0]
|
| 13 |
+
// return x
|
| 14 |
+
// This pass produces (after dead code elimination):
|
| 15 |
+
// def foo(a, b):
|
| 16 |
+
// return 1
|
| 17 |
+
//
|
| 18 |
+
// This optimization can only happen if the dict is not modified
|
| 19 |
+
// and the dict has constant, non overlapping keys.
|
| 20 |
+
//
|
| 21 |
+
// 2. len optimizations
|
| 22 |
+
// Given a function like this:
|
| 23 |
+
// def foo():
|
| 24 |
+
// d = {0 : 1}
|
| 25 |
+
// return len(d)
|
| 26 |
+
// This pass produces (after dead code elimination):
|
| 27 |
+
// def foo():
|
| 28 |
+
// return 1
|
| 29 |
+
//
|
| 30 |
+
// This has the same requirements as the getitem optimizations.
|
| 31 |
+
//
|
| 32 |
+
// Currently this is invoked as part of PeepholeOptimize
|
| 33 |
+
// return true if graph is modified.
|
| 34 |
+
TORCH_API bool PeepholeOptimizeDictIdioms(const std::shared_ptr<Graph>& graph);
|
| 35 |
+
|
| 36 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_list_idioms.h
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Peephole Optimizes List ops such as len(li) and li[1].
|
| 8 |
+
// 1. Construct/Unpack optimizations
|
| 9 |
+
// Given a function like this:
|
| 10 |
+
// def foo(a, b):
|
| 11 |
+
// li = [a, b]
|
| 12 |
+
// x, y = li
|
| 13 |
+
// return x, y
|
| 14 |
+
// This pass produces (after dead code elimination):
|
| 15 |
+
// def foo(a, b):
|
| 16 |
+
// return a, b
|
| 17 |
+
//
|
| 18 |
+
// This is only applied to lists that are not modified.
|
| 19 |
+
//
|
| 20 |
+
// 2. getitem optimizations
|
| 21 |
+
// Given a function like this:
|
| 22 |
+
// def foo(a, b):
|
| 23 |
+
// li = [a, b]
|
| 24 |
+
// x = li[0]
|
| 25 |
+
// return x
|
| 26 |
+
// This pass produces (after dead code elimination):
|
| 27 |
+
// def foo(a, b):
|
| 28 |
+
// return a
|
| 29 |
+
//
|
| 30 |
+
// This optimization can only happen if the list is not modified.
|
| 31 |
+
//
|
| 32 |
+
// 3. len optimizations
|
| 33 |
+
// Given a function like this:
|
| 34 |
+
// def foo():
|
| 35 |
+
// li = [1, 2]
|
| 36 |
+
// return len(li)
|
| 37 |
+
// This pass produces (after dead code elimination):
|
| 38 |
+
// def foo():
|
| 39 |
+
// return 2
|
| 40 |
+
//
|
| 41 |
+
// This has the same requirements as the getitem optimizations.
|
| 42 |
+
//
|
| 43 |
+
// 4. ListConstruct + ListConstruct
|
| 44 |
+
// Given a function like this:
|
| 45 |
+
// def foo():
|
| 46 |
+
// return [1, 2] + [3, 4]
|
| 47 |
+
// This pass produces (after dead code elimination):
|
| 48 |
+
// def foo():
|
| 49 |
+
// return [1, 2, 3, 4]
|
| 50 |
+
//
|
| 51 |
+
// This is only applied to lists that are not modified.
|
| 52 |
+
//
|
| 53 |
+
// 5. Slice
|
| 54 |
+
// Given a function like this:
|
| 55 |
+
// def foo():
|
| 56 |
+
// return [1, 2, 3, 4, 5][0:2]
|
| 57 |
+
// This pass produces (after deadcode elimination):
|
| 58 |
+
// def foo():
|
| 59 |
+
// return [1, 2]
|
| 60 |
+
//
|
| 61 |
+
// Currently this is invoked as part of PeepholeOptimize
|
| 62 |
+
// return true if graph is modified.
|
| 63 |
+
// If `refine_list_len` is true will attempt to refine the len of lists through
|
| 64 |
+
// len comparisons and assertions. This does not generally optimize pytorch
|
| 65 |
+
// programs so it is not called by default in PeepholeOptimize.
|
| 66 |
+
TORCH_API bool PeepholeOptimizeListIdioms(
|
| 67 |
+
const std::shared_ptr<Graph>& graph,
|
| 68 |
+
bool refine_list_len = false);
|
| 69 |
+
|
| 70 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/peephole_non_tensor.h
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// return true if graph is modified
|
| 8 |
+
// Optimizing General Graph Patterns that
|
| 9 |
+
// are not covered in peephole.cpp and peephole_list_idioms
|
| 10 |
+
TORCH_API bool PeepholeOptimizeNonTensor(const std::shared_ptr<Graph>& graph);
|
| 11 |
+
|
| 12 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/prepack_folding.h
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::jit {
|
| 7 |
+
|
| 8 |
+
using PrePackingOpsFilterFn = std::function<bool(Node*)>;
|
| 9 |
+
|
| 10 |
+
void PrePackingOpsFolder(
|
| 11 |
+
script::Module& m,
|
| 12 |
+
const PrePackingOpsFilterFn& is_foldable_op,
|
| 13 |
+
const std::string& attr_prefix);
|
| 14 |
+
|
| 15 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/dedup_module_uses.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
/** Recursively deduplicate multiple uses of the same module by
|
| 8 |
+
* creating an instance clone for each use of the module, which means
|
| 9 |
+
* the type will be the same as before and all the attributes will be
|
| 10 |
+
* copied, then we'll change the use of the original module to the use
|
| 11 |
+
* of cloned module in the Graph.
|
| 12 |
+
*
|
| 13 |
+
* This is done to ensure that modules can survive destructive passes
|
| 14 |
+
* without changing model behavior. For example, here:
|
| 15 |
+
*
|
| 16 |
+
* x = self.conv1(x)
|
| 17 |
+
* x = self.relu(x)
|
| 18 |
+
* x = self.conv2(x)
|
| 19 |
+
* x = self.relu(x)
|
| 20 |
+
*
|
| 21 |
+
* self.relu needs to be deduplicated for potential future destructive passes
|
| 22 |
+
* to work properly.
|
| 23 |
+
*/
|
| 24 |
+
TORCH_API void DedupModuleUses(Module& module);
|
| 25 |
+
|
| 26 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/finalize.h
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
#include <torch/csrc/jit/passes/quantization/quantization_type.h>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit {
|
| 8 |
+
|
| 9 |
+
/** \brief Backend specific pass to fuse dequantize - op - quantize calls
|
| 10 |
+
* as quantized_op calls.
|
| 11 |
+
*
|
| 12 |
+
* Right now this is a fusion for fbgemm backend and only works for quantized
|
| 13 |
+
* conv op, we'll extend to more ops and more backends in the future.
|
| 14 |
+
*
|
| 15 |
+
* Currently supported fusion:
|
| 16 |
+
* q(conv2d(dq(a), dq(w), dq(b))) --> to_nchw(fbgemm_conv2d(prepack(to_nhwc(a)),
|
| 17 |
+
* prepack(to_nhwc(w)),
|
| 18 |
+
* prepack(to_nhwc(b))))
|
| 19 |
+
*
|
| 20 |
+
* q(linear(dq(a), dq(w), dq(b))) --> to_nchw(fbgemm_linear(prepack(to_nhwc(a)),
|
| 21 |
+
* prepack(to_nhwc(w)),
|
| 22 |
+
* prepack(to_nhwc(b))))
|
| 23 |
+
*
|
| 24 |
+
* \param graph the graph we want to apply fusion
|
| 25 |
+
*/
|
| 26 |
+
TORCH_API void QuantFusion(
|
| 27 |
+
std::shared_ptr<Graph>& graph,
|
| 28 |
+
QuantType quant_type = QuantType::STATIC);
|
| 29 |
+
|
| 30 |
+
/** \brief Insert prepack and unpack function in graph
|
| 31 |
+
* We want add pack/unpack functions for quantized weight because later we want
|
| 32 |
+
* to fold the packed weight as an attribute of the module, in order to reduce
|
| 33 |
+
* the cost of packing the weight on the fly in quantized models.
|
| 34 |
+
*
|
| 35 |
+
* Each quantized op has it's corresponding prepack/unpack function,
|
| 36 |
+
* right now, we only need to do prepack/unpack for quantized::linear
|
| 37 |
+
* and quantized::conv2d.
|
| 38 |
+
*/
|
| 39 |
+
TORCH_API void InsertPrepackUnpack(std::shared_ptr<Graph>& graph);
|
| 40 |
+
|
| 41 |
+
/** \brief Insert pack and unpack function in all graphs
|
| 42 |
+
* of module
|
| 43 |
+
*
|
| 44 |
+
* Go through graphs of all the methods of all child modules
|
| 45 |
+
* and call InsertPrepackUnpack on the graph.
|
| 46 |
+
*/
|
| 47 |
+
TORCH_API void InsertPrepackUnpack(Module& module);
|
| 48 |
+
|
| 49 |
+
TORCH_API script::Module Finalize(
|
| 50 |
+
script::Module& module,
|
| 51 |
+
QuantType quant_type = QuantType::STATIC,
|
| 52 |
+
const std::vector<std::string>& preserved_attrs =
|
| 53 |
+
std::vector<std::string>());
|
| 54 |
+
|
| 55 |
+
TORCH_API void FoldQuantizedPrepackingOps(Module& module);
|
| 56 |
+
|
| 57 |
+
TORCH_API Module FinalizeOnDevicePTQ(
|
| 58 |
+
Module& module,
|
| 59 |
+
QuantType quant_type,
|
| 60 |
+
const std::string& method_name);
|
| 61 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/fusion_passes.h
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
TORCH_API void FuseQuantizedAddRelu(std::shared_ptr<Graph>& graph);
|
| 7 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/helper.h
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <torch/csrc/jit/api/module.h>
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/subgraph_matcher.h>
|
| 5 |
+
#include <torch/csrc/jit/passes/graph_rewrite_helper.h>
|
| 6 |
+
#include <torch/csrc/jit/passes/quantization/quantization_type.h>
|
| 7 |
+
|
| 8 |
+
#include <functional>
|
| 9 |
+
#include <regex>
|
| 10 |
+
|
| 11 |
+
namespace torch::jit {
|
| 12 |
+
|
| 13 |
+
using graph_rewrite_helper::getFuncName;
|
| 14 |
+
|
| 15 |
+
// Vector of a module and the name of its method
|
| 16 |
+
using ModuleMethodVector = std::vector<std::pair<Module, std::string>>;
|
| 17 |
+
// Map of quantization parameter name and value
|
| 18 |
+
// for example _scale, _zero_point,
|
| 19 |
+
// _scalar_type and _axis(for per channel quantization)
|
| 20 |
+
using QParamVector = std::vector<std::pair<std::string, IValue>>;
|
| 21 |
+
|
| 22 |
+
// =========== helper functions for Value =========
|
| 23 |
+
// Check if a value is weight, since we need to use weight observer
|
| 24 |
+
// for weight
|
| 25 |
+
TORCH_API bool isWeight(Value* v);
|
| 26 |
+
|
| 27 |
+
// Check if a value is bias for conv and linear, which we do not
|
| 28 |
+
// quantize
|
| 29 |
+
TORCH_API bool isBiasOfConvOrLinear(Value* v);
|
| 30 |
+
|
| 31 |
+
TORCH_API bool isEmbeddingBagNonInput(Value* v);
|
| 32 |
+
|
| 33 |
+
// Get the use as scalar input of clamp ops for the input value
|
| 34 |
+
std::optional<Use> getClampScalarInputUse(Value* v);
|
| 35 |
+
|
| 36 |
+
// For a given value `v`, get the list of values that we need to check
|
| 37 |
+
// if they are observed/quantized or not, if so, we can say the
|
| 38 |
+
// `v` is also observed/quantized, since we can derive
|
| 39 |
+
// the quantization parameters for `v` given the list of values
|
| 40 |
+
TORCH_API std::vector<Value*> getPassThroughInputs(Value* v);
|
| 41 |
+
|
| 42 |
+
// Clones the method by the name of orig_method_name into new_method_name method
|
| 43 |
+
TORCH_API void cloneMethod(
|
| 44 |
+
Module& module,
|
| 45 |
+
const std::string& orig_method_name,
|
| 46 |
+
const std::string& new_method_name);
|
| 47 |
+
|
| 48 |
+
// Check if a value in the graph is a Scalar value
|
| 49 |
+
TORCH_API bool isScalar(Value* v);
|
| 50 |
+
|
| 51 |
+
// Check if value is the input of the graph
|
| 52 |
+
TORCH_API bool hitGraphInput(Value* value);
|
| 53 |
+
|
| 54 |
+
// Converts a mangled name, such as
|
| 55 |
+
// __torch__.torch.ao.nn.quantized.modules.conv.___torch_mangle_7.Conv2d
|
| 56 |
+
// into an unmangled name, such as
|
| 57 |
+
// __torch__.torch.ao.nn.quantized.modules.conv.Conv2d
|
| 58 |
+
TORCH_API std::string removeTorchMangle(const std::string& orig_name);
|
| 59 |
+
|
| 60 |
+
// Return the module name that corresponds to the value.
|
| 61 |
+
TORCH_API std::optional<std::string> getModuleName(Value* value);
|
| 62 |
+
|
| 63 |
+
// =========== helper functions for Node =========
|
| 64 |
+
TORCH_API bool isSingleInputGeneralShapeAtenFunction(Node* n);
|
| 65 |
+
|
| 66 |
+
TORCH_API bool isSingleInputGeneralValueAtenFunction(Node* n);
|
| 67 |
+
|
| 68 |
+
TORCH_API bool isSingleInputGeneralCallFunction(Node* n);
|
| 69 |
+
|
| 70 |
+
TORCH_API bool isSingleInputGeneralAtenFunction(Node* n);
|
| 71 |
+
|
| 72 |
+
TORCH_API bool isClamp(Node* n);
|
| 73 |
+
|
| 74 |
+
// Check if the node will produce the same result regardless of whether
|
| 75 |
+
// the input tensor is quantized or not, example: aten::size
|
| 76 |
+
TORCH_API bool isTensorInfoNode(Node* n);
|
| 77 |
+
|
| 78 |
+
// Check if this the propagate op that has single input, e.g. aten::cat
|
| 79 |
+
TORCH_API bool isPropagateQuantSingleInputOp(Node* n);
|
| 80 |
+
|
| 81 |
+
// Check if this is the propagate op that has two inputs, e.g. aten::add
|
| 82 |
+
TORCH_API bool isPropagateQuantBinaryOp(Node* n);
|
| 83 |
+
|
| 84 |
+
// Check if this is the node that we'll quantize or not quantize depending on
|
| 85 |
+
// whether the input of the node is quantized, example: aten::cat
|
| 86 |
+
TORCH_API bool isPropagateQuantOp(Node* n);
|
| 87 |
+
|
| 88 |
+
// Check if the node is a binary op like aten::add and aten::mul and
|
| 89 |
+
// if the input 1 is a scalar, these ops will be quantized to
|
| 90 |
+
// quantized::{op}_scalar
|
| 91 |
+
TORCH_API bool isBinaryOpWithScalarInput(Node* n);
|
| 92 |
+
|
| 93 |
+
TORCH_API std::optional<std::tuple<c10::QScheme, QParamVector>> getFixedQParams(
|
| 94 |
+
Node* n);
|
| 95 |
+
|
| 96 |
+
// We don't want to analyze the graph for some `builtin` CallFunctions
|
| 97 |
+
// like `linear` because we want to preserve the op boundary
|
| 98 |
+
TORCH_API bool userDefinedCallFunction(Node* n);
|
| 99 |
+
|
| 100 |
+
// Check if the node has scalar input
|
| 101 |
+
TORCH_API bool hasScalarInput(Node* n);
|
| 102 |
+
|
| 103 |
+
// Check if a node is quantizable
|
| 104 |
+
TORCH_API bool nodeQuantizable(
|
| 105 |
+
Node* n,
|
| 106 |
+
QuantType quant_type = QuantType::STATIC);
|
| 107 |
+
|
| 108 |
+
// Nodes which only require quantization of weight value, eg. embedding_bag
|
| 109 |
+
bool isWeightOnlyStaticQuantOp(Node* n);
|
| 110 |
+
|
| 111 |
+
// Check if a use of the value is quantizable, this depends on
|
| 112 |
+
// both the use node and the offset
|
| 113 |
+
TORCH_API bool useQuantizable(const Use& use, QuantType quant_type);
|
| 114 |
+
|
| 115 |
+
// Given a CallFunction node, extract the graph of the called function
|
| 116 |
+
TORCH_API std::shared_ptr<Graph> getCallFunctionGraph(Node* n);
|
| 117 |
+
|
| 118 |
+
// Check if `use` is a CallFunction of name `func_name` and if value
|
| 119 |
+
// `v` is the nth argument (if provided) of the function
|
| 120 |
+
bool matchCallFuncToUse(
|
| 121 |
+
const Use& use,
|
| 122 |
+
const std::string& func_name,
|
| 123 |
+
std::optional<int> nth_arg);
|
| 124 |
+
|
| 125 |
+
// Check if `use` is a AtenFunction of name `func_name` and if value
|
| 126 |
+
// `v` is the nth argument (if provided) of the function
|
| 127 |
+
bool matchAtenFuncToUse(
|
| 128 |
+
const Use& use,
|
| 129 |
+
const std::string& func_name,
|
| 130 |
+
std::optional<int> nth_arg);
|
| 131 |
+
|
| 132 |
+
// =========== helper functions for Block =========
|
| 133 |
+
// checks if a block will always raise an Exception
|
| 134 |
+
TORCH_API bool alwaysRaisesException(Block* block);
|
| 135 |
+
|
| 136 |
+
// =========== helper functions for Module ==========
|
| 137 |
+
// TODO: remove
|
| 138 |
+
TORCH_API std::vector<std::string> getModuleAccessPath(
|
| 139 |
+
Value* instance,
|
| 140 |
+
Value* self);
|
| 141 |
+
// TODO: remove
|
| 142 |
+
TORCH_API Module
|
| 143 |
+
findChildModule(const Module& module, const std::vector<std::string>& path);
|
| 144 |
+
|
| 145 |
+
// Given an CallMethod node, get the module instance corresponding
|
| 146 |
+
// to the instance Value
|
| 147 |
+
// TODO: refactor all current uses of this function to the Opt one
|
| 148 |
+
TORCH_API Module getInvokedModule(Module& module, Node* n, Value* self);
|
| 149 |
+
|
| 150 |
+
// Given an CallMethod node, get the module instance corresponding
|
| 151 |
+
// to the instance Value if the instance is a module, otherwise return
|
| 152 |
+
// std::nullopt
|
| 153 |
+
std::optional<Module> getInvokedModuleOpt(
|
| 154 |
+
const Module& module,
|
| 155 |
+
Node* n,
|
| 156 |
+
Value* self);
|
| 157 |
+
|
| 158 |
+
// ==================== filter functions for matches ==============
|
| 159 |
+
// filter to check Value `vname` is a constant of int value `value`
|
| 160 |
+
bool is_int_constant(
|
| 161 |
+
const Match& match,
|
| 162 |
+
const std::unordered_map<std::string, Value*>& vmap,
|
| 163 |
+
const std::string& vname,
|
| 164 |
+
int value);
|
| 165 |
+
|
| 166 |
+
// filter to check if the %alpha argument of aten::add is constant 1
|
| 167 |
+
bool aten_add_alpha_is_one(
|
| 168 |
+
const Match& match,
|
| 169 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 170 |
+
|
| 171 |
+
// filter to check if the functional in CallFunction is relu
|
| 172 |
+
bool is_functional_relu(
|
| 173 |
+
const Match& match,
|
| 174 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 175 |
+
|
| 176 |
+
// filter to check if the module is torch.nn.ReLU
|
| 177 |
+
bool is_relu_module(
|
| 178 |
+
const Match& match,
|
| 179 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 180 |
+
|
| 181 |
+
bool is_linear_module(
|
| 182 |
+
const Match& match,
|
| 183 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 184 |
+
|
| 185 |
+
// TODO: add a macro to declare the filters
|
| 186 |
+
bool is_conv1d_module(
|
| 187 |
+
const Match& match,
|
| 188 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 189 |
+
|
| 190 |
+
bool is_conv2d_module(
|
| 191 |
+
const Match& match,
|
| 192 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 193 |
+
|
| 194 |
+
bool is_conv3d_module(
|
| 195 |
+
const Match& match,
|
| 196 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 197 |
+
|
| 198 |
+
bool is_conv_transpose1d_module(
|
| 199 |
+
const Match& match,
|
| 200 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 201 |
+
|
| 202 |
+
bool is_conv_transpose2d_module(
|
| 203 |
+
const Match& match,
|
| 204 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 205 |
+
|
| 206 |
+
bool is_batchnorm2d_module(
|
| 207 |
+
const Match& match,
|
| 208 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 209 |
+
|
| 210 |
+
bool is_batchnorm3d_module(
|
| 211 |
+
const Match& match,
|
| 212 |
+
const std::unordered_map<std::string, Value*>& vmap);
|
| 213 |
+
|
| 214 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/insert_observers.h
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/passes/quantization/quantization_type.h>
|
| 5 |
+
|
| 6 |
+
namespace std {
|
| 7 |
+
|
| 8 |
+
template <>
|
| 9 |
+
struct hash<torch::jit::Module> {
|
| 10 |
+
inline size_t operator()(const torch::jit::Module& arg) const {
|
| 11 |
+
return std::hash<c10::intrusive_ptr<c10::ivalue::Object>>()(arg._ivalue());
|
| 12 |
+
}
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
} // namespace std
|
| 16 |
+
|
| 17 |
+
namespace torch::jit {
|
| 18 |
+
|
| 19 |
+
using QConfig = std::tuple<Module, Module>;
|
| 20 |
+
using QConfigDict = std::unordered_map<std::string, std::optional<QConfig>>;
|
| 21 |
+
|
| 22 |
+
/** \brief Insert observer module and observer function call for
|
| 23 |
+
* the Tensors that needs to be observed.
|
| 24 |
+
*
|
| 25 |
+
* For each Tensor that needs to be observed in the method, insert observer
|
| 26 |
+
* module to the input module and add forward calls of observer to the specified
|
| 27 |
+
* method.
|
| 28 |
+
*
|
| 29 |
+
* \param module the input module
|
| 30 |
+
* \param method_name the method we want to insert observers for
|
| 31 |
+
* \param qconfig_dict the qconfig dictionary that specifies how
|
| 32 |
+
* each module is going to be quantized
|
| 33 |
+
* \param inplace whether we want to do inplace modification to the input module
|
| 34 |
+
* or clone the module
|
| 35 |
+
* \param is_dynamic whether the dynamic quantization script is being used.
|
| 36 |
+
*/
|
| 37 |
+
TORCH_API Module InsertObservers(
|
| 38 |
+
Module& module,
|
| 39 |
+
const std::string& method_name,
|
| 40 |
+
const QConfigDict& qconfig_dict,
|
| 41 |
+
bool inplace,
|
| 42 |
+
QuantType quant_type = QuantType::STATIC);
|
| 43 |
+
|
| 44 |
+
/** \brief Insert observer module and observer method for
|
| 45 |
+
* the Tensors that needs to be observed.
|
| 46 |
+
*
|
| 47 |
+
* For each Tensor that needs to be observed in the method, insert observer
|
| 48 |
+
* module to the input module and observe_<method-name> methods to the module.
|
| 49 |
+
* This method is clone of mehtod_name with forward calls of observer added.
|
| 50 |
+
*
|
| 51 |
+
* \param module the input module
|
| 52 |
+
* \param method_name the method we want to insert observers for
|
| 53 |
+
* \param qconfig_dict the qconfig dictionary that specifies how
|
| 54 |
+
* each module is going to be quantized
|
| 55 |
+
* \param inplace whether we want to do inplace modification to the input module
|
| 56 |
+
* or clone the module
|
| 57 |
+
* \param is_dynamic whether the dynamic quantization script is being used.
|
| 58 |
+
*/
|
| 59 |
+
TORCH_API Module InsertObserversForOnDevicePTQ(
|
| 60 |
+
Module& module,
|
| 61 |
+
const std::string& method_name,
|
| 62 |
+
const QConfigDict& qconfig_dict,
|
| 63 |
+
bool inplace,
|
| 64 |
+
QuantType quant_type = QuantType::STATIC);
|
| 65 |
+
|
| 66 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/insert_quant_dequant.h
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
#include <torch/csrc/jit/passes/quantization/quantization_type.h>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit {
|
| 8 |
+
|
| 9 |
+
/** Replicate quantize node for prim::If blocks, so that we can match
|
| 10 |
+
* quantization patterns in prim::If blocks
|
| 11 |
+
*/
|
| 12 |
+
TORCH_API void ReplicateQuant(std::shared_ptr<Graph>& graph);
|
| 13 |
+
|
| 14 |
+
/** Replicate dequantize node for each use, so that we can match
|
| 15 |
+
* quantization patterns
|
| 16 |
+
*/
|
| 17 |
+
TORCH_API void ReplicateDeQuant(std::shared_ptr<Graph>& graph);
|
| 18 |
+
|
| 19 |
+
/** \brief Insert quantize - dequantize calls to the Tensors
|
| 20 |
+
* that are observed in insert_observers pass
|
| 21 |
+
*
|
| 22 |
+
* For each Tensor that is observed, get the observer module and call
|
| 23 |
+
* calculate_qparam on the observer module to get quantization parameters
|
| 24 |
+
* and add quantize - int_repr - dequantize function calls using these
|
| 25 |
+
* parameters we also have special handling for quantizing "bias" right now.
|
| 26 |
+
*
|
| 27 |
+
* \param module the input module
|
| 28 |
+
* \param method_name the method we want to insert quantization calls for
|
| 29 |
+
*/
|
| 30 |
+
TORCH_API Module InsertQuantDeQuant(
|
| 31 |
+
Module& module,
|
| 32 |
+
const std::string& method_name,
|
| 33 |
+
bool inplace,
|
| 34 |
+
bool debug,
|
| 35 |
+
QuantType quant_type = QuantType::STATIC);
|
| 36 |
+
|
| 37 |
+
TORCH_API Module InsertQuantDeQuantOnDevicePTQ(
|
| 38 |
+
Module& module,
|
| 39 |
+
const std::string& method_name,
|
| 40 |
+
bool inplace,
|
| 41 |
+
bool debug,
|
| 42 |
+
QuantType quant_type = QuantType::STATIC);
|
| 43 |
+
|
| 44 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/quantization_patterns.h
ADDED
|
@@ -0,0 +1,1264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/irange.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
#include <torch/csrc/jit/ir/subgraph_matcher.h>
|
| 6 |
+
#include <torch/csrc/jit/jit_log.h>
|
| 7 |
+
#include <torch/csrc/jit/passes/quantization/helper.h>
|
| 8 |
+
#include <torch/csrc/jit/passes/subgraph_rewrite.h>
|
| 9 |
+
#include <string>
|
| 10 |
+
#include <unordered_map>
|
| 11 |
+
#include <utility>
|
| 12 |
+
|
| 13 |
+
namespace torch::jit {
|
| 14 |
+
|
| 15 |
+
struct QuantFusionInfo {
|
| 16 |
+
std::string quantized_op_name;
|
| 17 |
+
std::string pattern;
|
| 18 |
+
std::string replacement;
|
| 19 |
+
std::vector<MatchFilter> filters = {};
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
namespace {
|
| 23 |
+
std::string getExtraArgList(std::vector<std::string> extra_args) {
|
| 24 |
+
return std::accumulate(
|
| 25 |
+
extra_args.begin(),
|
| 26 |
+
extra_args.end(),
|
| 27 |
+
std::string(),
|
| 28 |
+
[](const std::string& acc, const std::string& arg) {
|
| 29 |
+
return acc + ", " + arg;
|
| 30 |
+
});
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// Get the pattern we want to replace the match with
|
| 34 |
+
std::string getAtenOpPattern(
|
| 35 |
+
const std::string& graph_header,
|
| 36 |
+
const std::string& op_name,
|
| 37 |
+
const std::vector<std::string>& extra_op_args,
|
| 38 |
+
bool scalar_args = false) {
|
| 39 |
+
std::vector<std::string> _extra_op_args = extra_op_args;
|
| 40 |
+
std::string aten_op_pattern = graph_header;
|
| 41 |
+
if (scalar_args) {
|
| 42 |
+
for (const auto& extra_arg : _extra_op_args) {
|
| 43 |
+
aten_op_pattern
|
| 44 |
+
.append(R"(
|
| 45 |
+
)")
|
| 46 |
+
.append(extra_arg)
|
| 47 |
+
.append("_scalar = aten::item(")
|
| 48 |
+
.append(extra_arg)
|
| 49 |
+
.append(")");
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
for (auto& _extra_op_arg : _extra_op_args) {
|
| 53 |
+
_extra_op_arg.append("_scalar");
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
const auto& extra_op_arg_list = getExtraArgList(std::move(_extra_op_args));
|
| 57 |
+
aten_op_pattern += R"(
|
| 58 |
+
%r = )";
|
| 59 |
+
aten_op_pattern += op_name + "(" + "%a_quant" + extra_op_arg_list + ")";
|
| 60 |
+
aten_op_pattern += R"(
|
| 61 |
+
return (%r) )";
|
| 62 |
+
return aten_op_pattern;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// generate ops for quantize pattern for a scalar value
|
| 66 |
+
std::string getQuantizeForScalar(const std::string& value) {
|
| 67 |
+
// 6 is `torch.float` ScalarType, we are creating a float scalar
|
| 68 |
+
// tensor from a scalar value
|
| 69 |
+
std::string quantize_pattern = R"(
|
| 70 |
+
)" +
|
| 71 |
+
value + "_float_scalar_type : int = prim::Constant[value=6]()";
|
| 72 |
+
quantize_pattern += R"(
|
| 73 |
+
)" +
|
| 74 |
+
value + "_none : None = prim::Constant()";
|
| 75 |
+
quantize_pattern += R"(
|
| 76 |
+
)" +
|
| 77 |
+
value + "_tensor : Tensor = aten::scalar_tensor(" + value + ", " + value +
|
| 78 |
+
"_float_scalar_type";
|
| 79 |
+
for ([[maybe_unused]] const auto i : c10::irange(3)) {
|
| 80 |
+
quantize_pattern += ", " + value + "_none";
|
| 81 |
+
}
|
| 82 |
+
quantize_pattern += ")";
|
| 83 |
+
quantize_pattern +=
|
| 84 |
+
R"(
|
| 85 |
+
)" +
|
| 86 |
+
value + "_quant = aten::quantize_per_tensor(" + value + "_tensor" +
|
| 87 |
+
getExtraArgList(
|
| 88 |
+
{value + "_scale", value + "_zero_point", value + "_dtype"}) +
|
| 89 |
+
")";
|
| 90 |
+
return quantize_pattern;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
std::string getDequantize(const std::string& value) {
|
| 94 |
+
return R"(
|
| 95 |
+
)" +
|
| 96 |
+
value + "_dequant = aten::dequantize(" + value + "_quant)";
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
std::string getItem(const std::string& value) {
|
| 100 |
+
return R"(
|
| 101 |
+
)" +
|
| 102 |
+
value + "_scalar : float = aten::item(" + value + "_dequant)";
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Patterns for the ops that inherit parameters from input
|
| 106 |
+
std::string getInputTensorQParamOpPattern(
|
| 107 |
+
const std::string& op_name,
|
| 108 |
+
const std::vector<std::string>& extra_op_args) {
|
| 109 |
+
const auto& extra_op_arg_list = getExtraArgList(extra_op_args);
|
| 110 |
+
std::string op_pattern = "graph(%a_quant" + extra_op_arg_list + "):" + R"(
|
| 111 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 112 |
+
%r = )" +
|
| 113 |
+
op_name + "(" + "%a_dequant" + extra_op_arg_list + ")" + R"(
|
| 114 |
+
%r_scale : float = aten::q_scale(%a_quant)
|
| 115 |
+
%r_zero_point : int = aten::q_zero_point(%a_quant)
|
| 116 |
+
%r_dtype : int = prim::dtype(%a_quant)
|
| 117 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 118 |
+
return (%r_quant) )";
|
| 119 |
+
return op_pattern;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// QuantFusionInfo for the ops that inherit parameters from input
|
| 123 |
+
QuantFusionInfo getInputTensorQParamOpFusionInfo(
|
| 124 |
+
const std::string& op_name,
|
| 125 |
+
const std::vector<std::string>& extra_op_args) {
|
| 126 |
+
std::string op_pattern =
|
| 127 |
+
getInputTensorQParamOpPattern(op_name, extra_op_args);
|
| 128 |
+
const auto& extra_op_arg_list = getExtraArgList(extra_op_args);
|
| 129 |
+
std::string graph_header = "graph(%a_quant" + extra_op_arg_list + "):";
|
| 130 |
+
std::string op_replacement =
|
| 131 |
+
getAtenOpPattern(graph_header, op_name, extra_op_args);
|
| 132 |
+
|
| 133 |
+
return {op_name, std::move(op_pattern), std::move(op_replacement)};
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// quant fusion for ops like `quantized::add_scalar`, `quantized::mul_scalar`
|
| 137 |
+
QuantFusionInfo getBinaryOpScalarFusionInfo(
|
| 138 |
+
const std::string& op_name,
|
| 139 |
+
const std::vector<std::string>& extra_op_args,
|
| 140 |
+
const std::string& quantized_op_name,
|
| 141 |
+
const std::vector<std::string>& extra_quantized_op_args,
|
| 142 |
+
const std::vector<MatchFilter>& filters = {}) {
|
| 143 |
+
std::string op_pattern =
|
| 144 |
+
getInputTensorQParamOpPattern(op_name, extra_op_args);
|
| 145 |
+
|
| 146 |
+
const auto& extra_op_arg_list = getExtraArgList(extra_op_args);
|
| 147 |
+
std::string graph_header = "graph(%a_quant" + extra_op_arg_list + "):";
|
| 148 |
+
std::string op_replacement = getAtenOpPattern(
|
| 149 |
+
graph_header, quantized_op_name, extra_quantized_op_args);
|
| 150 |
+
|
| 151 |
+
return {op_name, std::move(op_pattern), std::move(op_replacement), filters};
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
QuantFusionInfo getClampOpFusionInfo(
|
| 155 |
+
const std::string& op_name,
|
| 156 |
+
const std::vector<std::string>& extra_op_args) {
|
| 157 |
+
std::vector<std::string> header_args = extra_op_args;
|
| 158 |
+
std::vector<std::string> input_qparams = {"_scale", "_zero_point", "_dtype"};
|
| 159 |
+
for (const auto& arg : extra_op_args) {
|
| 160 |
+
for (const auto& qparam : input_qparams) {
|
| 161 |
+
header_args.push_back(arg + qparam);
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
for (const auto& qparam : input_qparams) {
|
| 165 |
+
header_args.push_back("%r" + qparam);
|
| 166 |
+
}
|
| 167 |
+
const auto& extra_header_arg_list = getExtraArgList(std::move(header_args));
|
| 168 |
+
std::string graph_header = "graph(%a_quant" + extra_header_arg_list + "):";
|
| 169 |
+
std::string op_pattern = graph_header;
|
| 170 |
+
for (const auto& arg : extra_op_args) {
|
| 171 |
+
op_pattern += getQuantizeForScalar(arg);
|
| 172 |
+
op_pattern += getDequantize(arg);
|
| 173 |
+
op_pattern += getItem(arg);
|
| 174 |
+
}
|
| 175 |
+
op_pattern += getDequantize("%a");
|
| 176 |
+
op_pattern += R"(
|
| 177 |
+
%r = )";
|
| 178 |
+
std::vector<std::string> scalar_extra_args;
|
| 179 |
+
scalar_extra_args.reserve(extra_op_args.size());
|
| 180 |
+
for (const auto& arg : extra_op_args) {
|
| 181 |
+
scalar_extra_args.push_back(arg + "_scalar");
|
| 182 |
+
}
|
| 183 |
+
op_pattern += op_name + "(" + "%a_dequant" +
|
| 184 |
+
getExtraArgList(std::move(scalar_extra_args)) + ")";
|
| 185 |
+
// IR pattern common to all ops that inherit qparam from input
|
| 186 |
+
op_pattern += R"(
|
| 187 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 188 |
+
return (%r_quant) )";
|
| 189 |
+
|
| 190 |
+
std::string aten_op_pattern =
|
| 191 |
+
getAtenOpPattern(graph_header, op_name, extra_op_args);
|
| 192 |
+
|
| 193 |
+
return {op_name, std::move(op_pattern), std::move(aten_op_pattern)};
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// Patterns for the ops that has fixed quantization parameters
|
| 197 |
+
QuantFusionInfo getFixedQParamOpFusionInfo(
|
| 198 |
+
const std::string& op_name,
|
| 199 |
+
const std::vector<std::string>& extra_op_args,
|
| 200 |
+
bool is_symmetric) {
|
| 201 |
+
const auto& extra_op_arg_list = getExtraArgList(extra_op_args);
|
| 202 |
+
std::string graph_header = "graph(%a_quant" + extra_op_arg_list + "):";
|
| 203 |
+
std::string op_pattern = graph_header;
|
| 204 |
+
op_pattern += R"(
|
| 205 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 206 |
+
%r = )";
|
| 207 |
+
op_pattern += op_name + "(" + "%a_dequant" + extra_op_arg_list + ")";
|
| 208 |
+
// IR pattern common to all ops with fixed quantization parameters for
|
| 209 |
+
// asymetric quantization
|
| 210 |
+
std::string asym_fixed_qparam_op_suffix = R"(
|
| 211 |
+
%r_scale : float = prim::Constant[value=0.00390625]()
|
| 212 |
+
%r_zero_point : int = prim::Constant[value=0]()
|
| 213 |
+
%r_dtype : int = prim::Constant[value=13]()
|
| 214 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 215 |
+
return (%r_quant) )";
|
| 216 |
+
|
| 217 |
+
std::string sym_fixed_qparam_op_suffix = R"(
|
| 218 |
+
%r_scale : float = prim::Constant[value=0.0078125]()
|
| 219 |
+
%r_zero_point : int = prim::Constant[value=128]()
|
| 220 |
+
%r_dtype : int = prim::Constant[value=13]()
|
| 221 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 222 |
+
return (%r_quant) )";
|
| 223 |
+
op_pattern +=
|
| 224 |
+
is_symmetric ? sym_fixed_qparam_op_suffix : asym_fixed_qparam_op_suffix;
|
| 225 |
+
|
| 226 |
+
std::string aten_op_pattern =
|
| 227 |
+
getAtenOpPattern(graph_header, op_name, extra_op_args);
|
| 228 |
+
|
| 229 |
+
return {op_name, std::move(op_pattern), std::move(aten_op_pattern)};
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// filter that checks %b_scalar is a scalar
|
| 233 |
+
bool input_b_is_scalar(
|
| 234 |
+
const Match& match,
|
| 235 |
+
const std::unordered_map<std::string, Value*>& vmap) {
|
| 236 |
+
const auto& match_vmap = match.values_map;
|
| 237 |
+
auto b_scalar = match_vmap.at(vmap.at("b_scalar"));
|
| 238 |
+
return isScalar(b_scalar);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// Patterns for ops that require observation for output quantization parameters
|
| 242 |
+
// Example:
|
| 243 |
+
//
|
| 244 |
+
// before fusion:
|
| 245 |
+
//
|
| 246 |
+
// graph(%a_quant, %r_scale, %r_zero_point, %r_dtype):
|
| 247 |
+
// %a_dequant = aten::dequantize(%a_quant)
|
| 248 |
+
// %r = {op_name}(%a_dequant, {extra_args})
|
| 249 |
+
// %r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point,
|
| 250 |
+
// %r_dtype) return (%r_quant)
|
| 251 |
+
//
|
| 252 |
+
// after fusion:
|
| 253 |
+
//
|
| 254 |
+
// graph(%a_quant, %r_scale, %r_zero_point, %r_dtype):
|
| 255 |
+
// %r_quant = {quantized_op_name}(%a_quant, {extra_args}, %r_scale,
|
| 256 |
+
// %r_zero_point) return (%r_quant)
|
| 257 |
+
QuantFusionInfo getObservedQParamOpFusionInfo(
|
| 258 |
+
const std::string& fp_op_name,
|
| 259 |
+
const std::string& q_op_name,
|
| 260 |
+
const std::vector<std::string>& fp_extra_args,
|
| 261 |
+
const std::vector<std::string>& q_extra_args) {
|
| 262 |
+
const auto& fp_extra_arg_list = getExtraArgList(fp_extra_args);
|
| 263 |
+
const auto& q_extra_arg_list = getExtraArgList(q_extra_args);
|
| 264 |
+
|
| 265 |
+
std::string op_pattern = "graph(%a_quant" + fp_extra_arg_list +
|
| 266 |
+
", %r_scale, %r_zero_point, %r_dtype):" + R"(
|
| 267 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 268 |
+
%r = )" +
|
| 269 |
+
fp_op_name + "(" + "%a_dequant" + fp_extra_arg_list + ")" + R"(
|
| 270 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 271 |
+
return (%r_quant) )";
|
| 272 |
+
|
| 273 |
+
std::string aten_op_pattern = "graph(%a_quant" + fp_extra_arg_list +
|
| 274 |
+
", %r_scale, %r_zero_point, %r_dtype):" + R"(
|
| 275 |
+
%r_quant = )" +
|
| 276 |
+
q_op_name + "(%a_quant" + q_extra_arg_list +
|
| 277 |
+
", %r_scale, %r_zero_point)" + R"(
|
| 278 |
+
return (%r_quant) )";
|
| 279 |
+
|
| 280 |
+
return {q_op_name, std::move(op_pattern), std::move(aten_op_pattern)};
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
} // namespace
|
| 284 |
+
|
| 285 |
+
static std::vector<QuantFusionInfo> quant_fusion_pattern_and_replacements() {
|
| 286 |
+
// aten::conv1d
|
| 287 |
+
std::string conv1d = R"(
|
| 288 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 289 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 290 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv1d_unpack(%packed_params)
|
| 291 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 292 |
+
%r = aten::conv1d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 293 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 294 |
+
return (%r_quant) )";
|
| 295 |
+
|
| 296 |
+
// aten::conv1d - aten::relu
|
| 297 |
+
std::string conv1d_relu = R"(
|
| 298 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 299 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 300 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv1d_unpack(%packed_params)
|
| 301 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 302 |
+
%conv_out = aten::conv1d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 303 |
+
%r = aten::relu(%conv_out)
|
| 304 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 305 |
+
return (%r_quant) )";
|
| 306 |
+
|
| 307 |
+
// aten::conv1d - aten::relu_
|
| 308 |
+
std::string conv1d_inplace_relu = R"(
|
| 309 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 310 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 311 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv1d_unpack(%packed_params)
|
| 312 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 313 |
+
%conv_out = aten::conv1d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 314 |
+
%r = aten::relu_(%conv_out)
|
| 315 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 316 |
+
return (%r_quant) )";
|
| 317 |
+
|
| 318 |
+
// quantized::conv1d
|
| 319 |
+
std::string quantized_conv1d = R"(
|
| 320 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 321 |
+
%r_quant = quantized::conv1d(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 322 |
+
return (%r_quant) )";
|
| 323 |
+
|
| 324 |
+
// quantized::conv1d_relu
|
| 325 |
+
std::string quantized_conv1d_relu = R"(
|
| 326 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 327 |
+
%r_quant = quantized::conv1d_relu(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 328 |
+
return (%r_quant) )";
|
| 329 |
+
|
| 330 |
+
// aten::conv2d
|
| 331 |
+
std::string conv2d = R"(
|
| 332 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 333 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 334 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv2d_unpack(%packed_params)
|
| 335 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 336 |
+
%r = aten::conv2d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 337 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 338 |
+
return (%r_quant) )";
|
| 339 |
+
|
| 340 |
+
// aten::conv2d - aten::relu
|
| 341 |
+
std::string conv2d_relu = R"(
|
| 342 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 343 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 344 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv2d_unpack(%packed_params)
|
| 345 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 346 |
+
%conv_out = aten::conv2d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 347 |
+
%r = aten::relu(%conv_out)
|
| 348 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 349 |
+
return (%r_quant) )";
|
| 350 |
+
|
| 351 |
+
// aten::conv2d - aten::relu_
|
| 352 |
+
std::string conv2d_inplace_relu = R"(
|
| 353 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 354 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 355 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv2d_unpack(%packed_params)
|
| 356 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 357 |
+
%conv_out = aten::conv2d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 358 |
+
%r = aten::relu_(%conv_out)
|
| 359 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 360 |
+
return (%r_quant) )";
|
| 361 |
+
|
| 362 |
+
// quantized::conv2d
|
| 363 |
+
std::string quantized_conv2d = R"(
|
| 364 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 365 |
+
%r_quant = quantized::conv2d(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 366 |
+
return (%r_quant) )";
|
| 367 |
+
|
| 368 |
+
// quantized::conv2d_relu
|
| 369 |
+
std::string quantized_conv2d_relu = R"(
|
| 370 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 371 |
+
%r_quant = quantized::conv2d_relu(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 372 |
+
return (%r_quant) )";
|
| 373 |
+
|
| 374 |
+
// aten::conv3d
|
| 375 |
+
std::string conv3d = R"(
|
| 376 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 377 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 378 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv3d_unpack(%packed_params)
|
| 379 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 380 |
+
%r = aten::conv3d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 381 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 382 |
+
return (%r_quant) )";
|
| 383 |
+
|
| 384 |
+
// aten::conv3d - aten::relu
|
| 385 |
+
std::string conv3d_relu = R"(
|
| 386 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 387 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 388 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv3d_unpack(%packed_params)
|
| 389 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 390 |
+
%conv_out = aten::conv3d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 391 |
+
%r = aten::relu(%conv_out)
|
| 392 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 393 |
+
return (%r_quant) )";
|
| 394 |
+
|
| 395 |
+
// aten::conv3d - aten::relu_
|
| 396 |
+
std::string conv3d_inplace_relu = R"(
|
| 397 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 398 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 399 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv3d_unpack(%packed_params)
|
| 400 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 401 |
+
%conv_out = aten::conv3d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 402 |
+
%r = aten::relu_(%conv_out)
|
| 403 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 404 |
+
return (%r_quant) )";
|
| 405 |
+
|
| 406 |
+
// quantized::conv3d
|
| 407 |
+
std::string quantized_conv3d = R"(
|
| 408 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 409 |
+
%r_quant = quantized::conv3d(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 410 |
+
return (%r_quant) )";
|
| 411 |
+
|
| 412 |
+
// quantized::conv3d_relu
|
| 413 |
+
std::string quantized_conv3d_relu = R"(
|
| 414 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %dilation, %groups):
|
| 415 |
+
%r_quant = quantized::conv3d_relu(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 416 |
+
return (%r_quant) )";
|
| 417 |
+
|
| 418 |
+
// aten::conv_transpose1d
|
| 419 |
+
std::string conv_transpose1d = R"(
|
| 420 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %output_padding, %groups, %dilation):
|
| 421 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 422 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv_transpose1d_unpack(%packed_params)
|
| 423 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 424 |
+
%r = aten::conv_transpose1d(%a_dequant, %w_dequant, %b, %stride, %padding, %output_padding, %groups, %dilation)
|
| 425 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 426 |
+
return (%r_quant) )";
|
| 427 |
+
|
| 428 |
+
// quantized::conv_transpose1d
|
| 429 |
+
std::string quantized_conv_transpose1d = R"(
|
| 430 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %output_padding, %groups, %dilation):
|
| 431 |
+
%r_quant = quantized::conv_transpose1d(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 432 |
+
return (%r_quant) )";
|
| 433 |
+
|
| 434 |
+
// aten::conv_transpose2d
|
| 435 |
+
std::string conv_transpose2d = R"(
|
| 436 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %output_padding, %groups, %dilation):
|
| 437 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 438 |
+
%w_quant : Tensor, %b : Tensor? = quantized::conv_transpose2d_unpack(%packed_params)
|
| 439 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 440 |
+
%r = aten::conv_transpose2d(%a_dequant, %w_dequant, %b, %stride, %padding, %output_padding, %groups, %dilation)
|
| 441 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 442 |
+
return (%r_quant) )";
|
| 443 |
+
|
| 444 |
+
// quantized::conv_transpose1d
|
| 445 |
+
std::string quantized_conv_transpose2d = R"(
|
| 446 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype, %stride, %padding, %output_padding, %groups, %dilation):
|
| 447 |
+
%r_quant = quantized::conv_transpose2d(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 448 |
+
return (%r_quant) )";
|
| 449 |
+
|
| 450 |
+
std::string add_relu = R"(
|
| 451 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 452 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 453 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 454 |
+
%r_add = aten::add(%a_dequant, %b_dequant, %alpha)
|
| 455 |
+
%r_relu = aten::relu(%r_add)
|
| 456 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 457 |
+
return (%r) )";
|
| 458 |
+
|
| 459 |
+
std::string add_inplace_relu = R"(
|
| 460 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 461 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 462 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 463 |
+
%r_add = aten::add(%a_dequant, %b_dequant, %alpha)
|
| 464 |
+
%r_relu = aten::relu_(%r_add)
|
| 465 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 466 |
+
return (%r) )";
|
| 467 |
+
|
| 468 |
+
std::string inplace_add_relu = R"(
|
| 469 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 470 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 471 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 472 |
+
%r_add = aten::add_(%a_dequant, %b_dequant, %alpha)
|
| 473 |
+
%r_relu = aten::relu(%r_add)
|
| 474 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 475 |
+
return (%r) )";
|
| 476 |
+
|
| 477 |
+
std::string inplace_add_inplace_relu = R"(
|
| 478 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 479 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 480 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 481 |
+
%r_add = aten::add_(%a_dequant, %b_dequant, %alpha)
|
| 482 |
+
%r_relu = aten::relu_(%r_add)
|
| 483 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 484 |
+
return (%r) )";
|
| 485 |
+
|
| 486 |
+
std::string quantized_add_relu = R"(
|
| 487 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 488 |
+
%r = quantized::add_relu(%a_quant, %b_quant, %scale, %zero_point)
|
| 489 |
+
return (%r) )";
|
| 490 |
+
|
| 491 |
+
// aten::linear
|
| 492 |
+
std::string linear = R"(
|
| 493 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype):
|
| 494 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 495 |
+
%w_quant : Tensor, %b : Tensor? = quantized::linear_unpack(%packed_params)
|
| 496 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 497 |
+
%r = aten::linear(%a_dequant, %w_dequant, %b)
|
| 498 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 499 |
+
return (%r_quant) )";
|
| 500 |
+
|
| 501 |
+
std::string linear_relu = R"(
|
| 502 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype):
|
| 503 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 504 |
+
%w_quant : Tensor, %b : Tensor? = quantized::linear_unpack(%packed_params)
|
| 505 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 506 |
+
%linear_out = aten::linear(%a_dequant, %w_dequant, %b)
|
| 507 |
+
%r = aten::relu(%linear_out)
|
| 508 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 509 |
+
return (%r_quant) )";
|
| 510 |
+
|
| 511 |
+
std::string linear_inplace_relu = R"(
|
| 512 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype):
|
| 513 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 514 |
+
%w_quant : Tensor, %b : Tensor? = quantized::linear_unpack(%packed_params)
|
| 515 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 516 |
+
%linear_out = aten::linear(%a_dequant, %w_dequant, %b)
|
| 517 |
+
%r = aten::relu_(%linear_out)
|
| 518 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 519 |
+
return (%r_quant) )";
|
| 520 |
+
|
| 521 |
+
// quantized::linear
|
| 522 |
+
std::string quantized_linear = R"(
|
| 523 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype):
|
| 524 |
+
%r = quantized::linear(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 525 |
+
return (%r) )";
|
| 526 |
+
|
| 527 |
+
std::string quantized_linear_relu = R"(
|
| 528 |
+
graph(%a_quant, %packed_params, %r_scale, %r_zero_point, %r_dtype):
|
| 529 |
+
%r = quantized::linear_relu(%a_quant, %packed_params, %r_scale, %r_zero_point)
|
| 530 |
+
return (%r) )";
|
| 531 |
+
|
| 532 |
+
std::string cat = R"(
|
| 533 |
+
graph(%input_quant, %dim, %r_scale, %r_zero_point, %r_dtype):
|
| 534 |
+
%input_dequant = aten::dequantize(%input_quant)
|
| 535 |
+
%r = aten::cat(%input_dequant, %dim)
|
| 536 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 537 |
+
return (%r_quant) )";
|
| 538 |
+
|
| 539 |
+
std::string quantized_cat = R"(
|
| 540 |
+
graph(%input_quant, %dim, %r_scale, %r_zero_point, %r_dtype):
|
| 541 |
+
%r_quant = quantized::cat(%input_quant, %dim, %r_scale, %r_zero_point)
|
| 542 |
+
return (%r_quant) )";
|
| 543 |
+
|
| 544 |
+
// aten::add
|
| 545 |
+
std::string add = R"(
|
| 546 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 547 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 548 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 549 |
+
%r_add = aten::add(%a_dequant, %b_dequant, %alpha)
|
| 550 |
+
%r = aten::quantize_per_tensor(%r_add, %scale, %zero_point, %dtype)
|
| 551 |
+
return (%r) )";
|
| 552 |
+
|
| 553 |
+
// TODO: add %dtype after when https://github.com/pytorch/pytorch/issues/34351
|
| 554 |
+
// is fixed
|
| 555 |
+
// quantized::add
|
| 556 |
+
std::string quantized_add = R"(
|
| 557 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 558 |
+
%r = quantized::add(%a_quant, %b_quant, %scale, %zero_point)
|
| 559 |
+
return (%r) )";
|
| 560 |
+
|
| 561 |
+
// aten::add_
|
| 562 |
+
std::string inplace_add = R"(
|
| 563 |
+
graph(%a_quant, %b_quant, %alpha, %scale, %zero_point, %dtype):
|
| 564 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 565 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 566 |
+
%r_add = aten::add_(%a_dequant, %b_dequant, %alpha)
|
| 567 |
+
%r = aten::quantize_per_tensor(%r_add, %scale, %zero_point, %dtype)
|
| 568 |
+
return (%r) )";
|
| 569 |
+
|
| 570 |
+
auto add_scalar = getBinaryOpScalarFusionInfo(
|
| 571 |
+
"aten::add",
|
| 572 |
+
{"%b_scalar", "%alpha"},
|
| 573 |
+
"quantized::add_scalar",
|
| 574 |
+
{"%b_scalar"},
|
| 575 |
+
{aten_add_alpha_is_one, input_b_is_scalar});
|
| 576 |
+
|
| 577 |
+
auto add_scalar_out = getBinaryOpScalarFusionInfo(
|
| 578 |
+
"aten::add_",
|
| 579 |
+
{"%b_scalar", "%alpha"},
|
| 580 |
+
"quantized::add_scalar_out",
|
| 581 |
+
{"%b_scalar", "%a_quant"},
|
| 582 |
+
{aten_add_alpha_is_one, input_b_is_scalar});
|
| 583 |
+
|
| 584 |
+
// quantized::add_scalar_relu -- fusing quantized::add_scalar
|
| 585 |
+
// and aten::relu
|
| 586 |
+
auto quantized_add_scalar_relu_pattern = R"(
|
| 587 |
+
graph(%a_quant, %b_scalar):
|
| 588 |
+
%r_add = quantized::add_scalar(%a_quant, %b_scalar)
|
| 589 |
+
%r = aten::relu(%r_add)
|
| 590 |
+
return (%r) )";
|
| 591 |
+
|
| 592 |
+
auto quantized_add_scalar_inplace_relu_pattern = R"(
|
| 593 |
+
graph(%a_quant, %b_scalar):
|
| 594 |
+
%r_add = quantized::add_scalar(%a_quant, %b_scalar)
|
| 595 |
+
%r = aten::relu_(%r_add)
|
| 596 |
+
return (%r) )";
|
| 597 |
+
|
| 598 |
+
auto quantized_add_scalar_relu_replacement = R"(
|
| 599 |
+
graph(%a_quant, %b_scalar):
|
| 600 |
+
%r = quantized::add_scalar_relu(%a_quant, %b_scalar)
|
| 601 |
+
return (%r) )";
|
| 602 |
+
|
| 603 |
+
// quantized::add_scalar_relu_out -- fusing quantized::add_scalarOut
|
| 604 |
+
// and aten::relu
|
| 605 |
+
auto quantized_add_scalar_relu_out_pattern = R"(
|
| 606 |
+
graph(%a_quant, %b_scalar):
|
| 607 |
+
%r_add = quantized::add_scalar_out(%a_quant, %b_scalar, %a_quant)
|
| 608 |
+
%r = aten::relu(%r_add)
|
| 609 |
+
return (%r) )";
|
| 610 |
+
|
| 611 |
+
auto quantized_add_scalar_inplace_relu_out_pattern = R"(
|
| 612 |
+
graph(%a_quant, %b_scalar):
|
| 613 |
+
%r_add = quantized::add_scalar_out(%a_quant, %b_scalar, %a_quant)
|
| 614 |
+
%r = aten::relu_(%r_add)
|
| 615 |
+
return (%r) )";
|
| 616 |
+
|
| 617 |
+
auto quantized_add_scalar_relu_out_replacement = R"(
|
| 618 |
+
graph(%a_quant, %b_scalar):
|
| 619 |
+
%r = quantized::add_scalar_relu_out(%a_quant, %b_scalar, %a_quant)
|
| 620 |
+
return (%r) )";
|
| 621 |
+
|
| 622 |
+
// quantized::batch_norm
|
| 623 |
+
std::string batch_norm = R"(
|
| 624 |
+
graph(%a_quant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7, %scale, %zero_point, %scalar_type):
|
| 625 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 626 |
+
%r_bn = aten::batch_norm(%a_dequant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7)
|
| 627 |
+
%r = aten::quantize_per_tensor(%r_bn, %scale, %zero_point, %scalar_type)
|
| 628 |
+
return (%r) )";
|
| 629 |
+
std::string quantized_batch_norm = R"(
|
| 630 |
+
graph(%a_quant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7, %scale, %zero_point, %scalar_type):
|
| 631 |
+
%r = quantized::batch_norm(%a_quant, %weight, %bias, %mean, %var, %eps, %scale, %zero_point)
|
| 632 |
+
return (%r) )";
|
| 633 |
+
|
| 634 |
+
std::string batch_norm_relu = R"(
|
| 635 |
+
graph(%a_quant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7, %scale, %zero_point, %scalar_type):
|
| 636 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 637 |
+
%bn_out = aten::batch_norm(%a_dequant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7)
|
| 638 |
+
%relu = aten::relu(%bn_out)
|
| 639 |
+
%r = aten::quantize_per_tensor(%relu, %scale, %zero_point, %scalar_type)
|
| 640 |
+
return (%r) )";
|
| 641 |
+
std::string batch_norm_inplace_relu = R"(
|
| 642 |
+
graph(%a_quant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7, %scale, %zero_point, %scalar_type):
|
| 643 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 644 |
+
%bn_out = aten::batch_norm(%a_dequant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7)
|
| 645 |
+
%relu = aten::relu_(%bn_out)
|
| 646 |
+
%r = aten::quantize_per_tensor(%relu, %scale, %zero_point, %scalar_type)
|
| 647 |
+
return (%r) )";
|
| 648 |
+
|
| 649 |
+
std::string quantized_batch_norm_relu = R"(
|
| 650 |
+
graph(%a_quant, %weight, %bias, %mean, %var, %training, %eaf, %eps, %7, %scale, %zero_point, %scalar_type):
|
| 651 |
+
%r = quantized::batch_norm_relu(%a_quant, %weight, %bias, %mean, %var, %eps, %scale, %zero_point)
|
| 652 |
+
return (%r) )";
|
| 653 |
+
|
| 654 |
+
// aten::mul
|
| 655 |
+
std::string mul = R"(
|
| 656 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 657 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 658 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 659 |
+
%r_mul = aten::mul(%a_dequant, %b_dequant)
|
| 660 |
+
%r = aten::quantize_per_tensor(%r_mul, %scale, %zero_point, %dtype)
|
| 661 |
+
return (%r) )";
|
| 662 |
+
|
| 663 |
+
// aten::mul_
|
| 664 |
+
std::string inplace_mul = R"(
|
| 665 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 666 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 667 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 668 |
+
%r_mul = aten::mul_(%a_dequant, %b_dequant)
|
| 669 |
+
%r = aten::quantize_per_tensor(%r_mul, %scale, %zero_point, %dtype)
|
| 670 |
+
return (%r) )";
|
| 671 |
+
|
| 672 |
+
// quantized::mul
|
| 673 |
+
std::string quantized_mul = R"(
|
| 674 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 675 |
+
%r = quantized::mul(%a_quant, %b_quant, %scale, %zero_point)
|
| 676 |
+
return (%r) )";
|
| 677 |
+
|
| 678 |
+
auto mul_scalar = getBinaryOpScalarFusionInfo(
|
| 679 |
+
"aten::mul",
|
| 680 |
+
{"%b_scalar"},
|
| 681 |
+
"quantized::mul_scalar",
|
| 682 |
+
{"%b_scalar"},
|
| 683 |
+
{input_b_is_scalar});
|
| 684 |
+
|
| 685 |
+
auto mul_scalar_out = getBinaryOpScalarFusionInfo(
|
| 686 |
+
"aten::mul_",
|
| 687 |
+
{"%b_scalar"},
|
| 688 |
+
"quantized::mul_scalar_out",
|
| 689 |
+
{"%b_scalar", "%a_quant"},
|
| 690 |
+
{input_b_is_scalar});
|
| 691 |
+
|
| 692 |
+
// quantized::mul_relu
|
| 693 |
+
std::string mul_relu = R"(
|
| 694 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 695 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 696 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 697 |
+
%r_mul = aten::mul(%a_dequant, %b_dequant)
|
| 698 |
+
%r_relu = aten::relu(%r_mul)
|
| 699 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 700 |
+
return (%r) )";
|
| 701 |
+
|
| 702 |
+
std::string mul_inplace_relu = R"(
|
| 703 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 704 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 705 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 706 |
+
%r_mul = aten::mul(%a_dequant, %b_dequant)
|
| 707 |
+
%r_relu = aten::relu_(%r_mul)
|
| 708 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 709 |
+
return (%r) )";
|
| 710 |
+
|
| 711 |
+
std::string inplace_mul_relu = R"(
|
| 712 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 713 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 714 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 715 |
+
%r_mul = aten::mul_(%a_dequant, %b_dequant)
|
| 716 |
+
%r_relu = aten::relu(%r_mul)
|
| 717 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 718 |
+
return (%r) )";
|
| 719 |
+
|
| 720 |
+
std::string inplace_mul_inplace_relu = R"(
|
| 721 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 722 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 723 |
+
%b_dequant = aten::dequantize(%b_quant)
|
| 724 |
+
%r_mul = aten::mul_(%a_dequant, %b_dequant)
|
| 725 |
+
%r_relu = aten::relu_(%r_mul)
|
| 726 |
+
%r = aten::quantize_per_tensor(%r_relu, %scale, %zero_point, %dtype)
|
| 727 |
+
return (%r) )";
|
| 728 |
+
|
| 729 |
+
std::string quantized_mul_relu = R"(
|
| 730 |
+
graph(%a_quant, %b_quant, %scale, %zero_point, %dtype):
|
| 731 |
+
%r = quantized::mul_relu(%a_quant, %b_quant, %scale, %zero_point)
|
| 732 |
+
return (%r) )";
|
| 733 |
+
|
| 734 |
+
// quantized::mul_scalar_relu -- fusing quantized::mul_scalar
|
| 735 |
+
// and aten::relu
|
| 736 |
+
auto quantized_mul_scalar_relu_pattern = R"(
|
| 737 |
+
graph(%a_quant, %b_scalar):
|
| 738 |
+
%r_mul = quantized::mul_scalar(%a_quant, %b_scalar)
|
| 739 |
+
%r = aten::relu(%r_mul)
|
| 740 |
+
return (%r) )";
|
| 741 |
+
|
| 742 |
+
auto quantized_mul_scalar_inplace_relu_pattern = R"(
|
| 743 |
+
graph(%a_quant, %b_scalar):
|
| 744 |
+
%r_mul = quantized::mul_scalar(%a_quant, %b_scalar)
|
| 745 |
+
%r = aten::relu_(%r_mul)
|
| 746 |
+
return (%r) )";
|
| 747 |
+
|
| 748 |
+
auto quantized_mul_scalar_relu_replacement = R"(
|
| 749 |
+
graph(%a_quant, %b_scalar):
|
| 750 |
+
%r = quantized::mul_scalar_relu(%a_quant, %b_scalar)
|
| 751 |
+
return (%r) )";
|
| 752 |
+
|
| 753 |
+
// quantized::mul_scalar_relu_out -- fusing quantized::mul_scalarOut
|
| 754 |
+
// and aten::relu
|
| 755 |
+
auto quantized_mul_scalar_relu_out_pattern = R"(
|
| 756 |
+
graph(%a_quant, %b_scalar):
|
| 757 |
+
%r_mul = quantized::mul_scalar_out(%a_quant, %b_scalar, %a_quant)
|
| 758 |
+
%r = aten::relu(%r_mul)
|
| 759 |
+
return (%r) )";
|
| 760 |
+
|
| 761 |
+
auto quantized_mul_scalar_inplace_relu_out_pattern = R"(
|
| 762 |
+
graph(%a_quant, %b_scalar):
|
| 763 |
+
%r_mul = quantized::mul_scalar_out(%a_quant, %b_scalar, %a_quant)
|
| 764 |
+
%r = aten::relu_(%r_mul)
|
| 765 |
+
return (%r) )";
|
| 766 |
+
|
| 767 |
+
auto quantized_mul_scalar_relu_out_replacement = R"(
|
| 768 |
+
graph(%a_quant, %b_scalar):
|
| 769 |
+
%r = quantized::mul_scalar_relu_out(%a_quant, %b_scalar, %a_quant)
|
| 770 |
+
return (%r) )";
|
| 771 |
+
|
| 772 |
+
// quantized::elu
|
| 773 |
+
std::string elu = R"(
|
| 774 |
+
graph(%a_quant, %alpha, %scale, %input_scale, %r_scale, %r_zero_point, %r_dtype):
|
| 775 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 776 |
+
%r = aten::elu(%a_dequant, %alpha, %scale, %input_scale)
|
| 777 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 778 |
+
return (%r_quant) )";
|
| 779 |
+
|
| 780 |
+
std::string quantized_elu = R"(
|
| 781 |
+
graph(%a_quant, %alpha, %scale, %input_scale, %r_scale, %r_zero_point, %r_dtype):
|
| 782 |
+
%r_quant = quantized::elu(%a_quant, %r_scale, %r_zero_point, %alpha, %scale, %input_scale)
|
| 783 |
+
return (%r_quant) )";
|
| 784 |
+
|
| 785 |
+
std::string elu_ = R"(
|
| 786 |
+
graph(%a_quant, %alpha, %scale, %input_scale, %r_scale, %r_zero_point, %r_dtype):
|
| 787 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 788 |
+
%r = aten::elu_(%a_dequant, %alpha, %scale, %input_scale)
|
| 789 |
+
%r_quant = aten::quantize_per_tensor(%r, %r_scale, %r_zero_point, %r_dtype)
|
| 790 |
+
return (%r_quant) )";
|
| 791 |
+
|
| 792 |
+
// ============= General Ops that inherit quantization parameters from input
|
| 793 |
+
// tensor =============
|
| 794 |
+
auto avg_pool1d = getInputTensorQParamOpFusionInfo(
|
| 795 |
+
"aten::avg_pool1d",
|
| 796 |
+
{"%kernel_size",
|
| 797 |
+
"%stride",
|
| 798 |
+
"%padding",
|
| 799 |
+
"%ceil_mode",
|
| 800 |
+
"%count_include_pad"});
|
| 801 |
+
|
| 802 |
+
auto avg_pool2d = getInputTensorQParamOpFusionInfo(
|
| 803 |
+
"aten::avg_pool2d",
|
| 804 |
+
{"%kernel_size",
|
| 805 |
+
"%stride",
|
| 806 |
+
"%padding",
|
| 807 |
+
"%ceil_mode",
|
| 808 |
+
"%count_include_pad",
|
| 809 |
+
"%divisor_override"});
|
| 810 |
+
|
| 811 |
+
auto avg_pool3d = getInputTensorQParamOpFusionInfo(
|
| 812 |
+
"aten::avg_pool3d",
|
| 813 |
+
{"%kernel_size",
|
| 814 |
+
"%stride",
|
| 815 |
+
"%padding",
|
| 816 |
+
"%ceil_mode",
|
| 817 |
+
"%count_include_pad",
|
| 818 |
+
"%divisor_override"});
|
| 819 |
+
|
| 820 |
+
auto adaptive_avg_pool1d = getInputTensorQParamOpFusionInfo(
|
| 821 |
+
"aten::adaptive_avg_pool1d", {"%output_size"});
|
| 822 |
+
|
| 823 |
+
auto adaptive_avg_pool2d = getInputTensorQParamOpFusionInfo(
|
| 824 |
+
"aten::adaptive_avg_pool2d", {"%output_size"});
|
| 825 |
+
|
| 826 |
+
auto adaptive_avg_pool3d = getInputTensorQParamOpFusionInfo(
|
| 827 |
+
"aten::adaptive_avg_pool3d", {"%output_size"});
|
| 828 |
+
|
| 829 |
+
auto mean1 = getInputTensorQParamOpFusionInfo("aten::mean", {"%dim"});
|
| 830 |
+
|
| 831 |
+
auto mean2 = getInputTensorQParamOpFusionInfo(
|
| 832 |
+
"aten::mean", {"%dim", "%keepdim", "%out"});
|
| 833 |
+
|
| 834 |
+
auto upsample_nearest1d_vec = getInputTensorQParamOpFusionInfo(
|
| 835 |
+
"aten::upsample_nearest1d", {"%output_size", "%scale_factors"});
|
| 836 |
+
|
| 837 |
+
auto upsample_nearest2d_vec = getInputTensorQParamOpFusionInfo(
|
| 838 |
+
"aten::upsample_nearest2d", {"%output_size", "%scale_factors"});
|
| 839 |
+
|
| 840 |
+
auto upsample_nearest3d_vec = getInputTensorQParamOpFusionInfo(
|
| 841 |
+
"aten::upsample_nearest3d", {"%output_size", "%scale_factors"});
|
| 842 |
+
|
| 843 |
+
auto upsample_linear1d_vec = getInputTensorQParamOpFusionInfo(
|
| 844 |
+
"aten::upsample_linear1d",
|
| 845 |
+
{"%output_size", "%align_corners", "%scale_factors"});
|
| 846 |
+
|
| 847 |
+
auto upsample_bilinear2d_vec = getInputTensorQParamOpFusionInfo(
|
| 848 |
+
"aten::upsample_bilinear2d",
|
| 849 |
+
{"%output_size", "%align_corners", "%scale_factors"});
|
| 850 |
+
|
| 851 |
+
auto upsample_trilinear3d_vec = getInputTensorQParamOpFusionInfo(
|
| 852 |
+
"aten::upsample_trilinear3d",
|
| 853 |
+
{"%output_size", "%align_corners", "%scale_factors"});
|
| 854 |
+
|
| 855 |
+
auto upsample_nearest1d = getInputTensorQParamOpFusionInfo(
|
| 856 |
+
"aten::upsample_nearest1d", {"%output_size", "%scales"});
|
| 857 |
+
|
| 858 |
+
auto upsample_nearest2d = getInputTensorQParamOpFusionInfo(
|
| 859 |
+
"aten::upsample_nearest2d", {"%output_size", "%scale_h", "%scale_w"});
|
| 860 |
+
|
| 861 |
+
auto upsample_nearest3d = getInputTensorQParamOpFusionInfo(
|
| 862 |
+
"aten::upsample_nearest3d",
|
| 863 |
+
{"%output_size", "%scale_d", "%scale_h", "%scale_w"});
|
| 864 |
+
|
| 865 |
+
auto upsample_linear1d = getInputTensorQParamOpFusionInfo(
|
| 866 |
+
"aten::upsample_linear1d", {"%output_size", "%align_corners", "%scales"});
|
| 867 |
+
|
| 868 |
+
auto upsample_bilinear2d = getInputTensorQParamOpFusionInfo(
|
| 869 |
+
"aten::upsample_bilinear2d",
|
| 870 |
+
{"%output_size", "%align_corners", "%scale_h", "%scale_w"});
|
| 871 |
+
|
| 872 |
+
auto upsample_trilinear3d = getInputTensorQParamOpFusionInfo(
|
| 873 |
+
"aten::upsample_trilinear3d",
|
| 874 |
+
{"%output_size", "%align_corners", "%scale_d", "%scale_h", "%scale_w"});
|
| 875 |
+
|
| 876 |
+
auto clamp = getClampOpFusionInfo("aten::clamp", {"%min", "%max"});
|
| 877 |
+
|
| 878 |
+
auto hardtanh = getClampOpFusionInfo("aten::hardtanh", {"%min", "%max"});
|
| 879 |
+
|
| 880 |
+
auto hardtanh_ = getClampOpFusionInfo("aten::hardtanh_", {"%min", "%max"});
|
| 881 |
+
|
| 882 |
+
auto leaky_relu =
|
| 883 |
+
getInputTensorQParamOpFusionInfo("aten::leaky_relu", {"%negative_slope"});
|
| 884 |
+
|
| 885 |
+
auto leaky_relu_ = getInputTensorQParamOpFusionInfo(
|
| 886 |
+
"aten::leaky_relu_", {"%negative_slope"});
|
| 887 |
+
|
| 888 |
+
// Ops with fixed quantization parameters
|
| 889 |
+
auto hardsigmoid = getFixedQParamOpFusionInfo("aten::hardsigmoid", {}, false);
|
| 890 |
+
|
| 891 |
+
auto hardsigmoid_ =
|
| 892 |
+
getFixedQParamOpFusionInfo("aten::hardsigmoid_", {}, false);
|
| 893 |
+
|
| 894 |
+
auto sigmoid = getFixedQParamOpFusionInfo("aten::sigmoid", {}, false);
|
| 895 |
+
|
| 896 |
+
auto sigmoid_ = getFixedQParamOpFusionInfo("aten::sigmoid_", {}, false);
|
| 897 |
+
|
| 898 |
+
auto tanh = getFixedQParamOpFusionInfo("aten::tanh", {}, true);
|
| 899 |
+
|
| 900 |
+
auto tanh_ = getFixedQParamOpFusionInfo("aten::tanh_", {}, true);
|
| 901 |
+
|
| 902 |
+
auto hardswish = getObservedQParamOpFusionInfo(
|
| 903 |
+
"aten::hardswish", "quantized::hardswish", {}, {});
|
| 904 |
+
|
| 905 |
+
auto hardswish_ = getObservedQParamOpFusionInfo(
|
| 906 |
+
"aten::hardswish_", "quantized::hardswish", {}, {});
|
| 907 |
+
|
| 908 |
+
auto layer_norm = getObservedQParamOpFusionInfo(
|
| 909 |
+
"aten::layer_norm",
|
| 910 |
+
"quantized::layer_norm",
|
| 911 |
+
{"%normalized_shape", "%weight", "%bias", "%eps", "%cudnn_enabled"},
|
| 912 |
+
{"%normalized_shape", "%weight", "%bias", "%eps"});
|
| 913 |
+
|
| 914 |
+
auto group_norm = getObservedQParamOpFusionInfo(
|
| 915 |
+
"aten::group_norm",
|
| 916 |
+
"quantized::group_norm",
|
| 917 |
+
{"%num_groups", "%weight", "%bias", "%eps", "%cudnn_enabled"},
|
| 918 |
+
{"%num_groups", "%weight", "%bias", "%eps"});
|
| 919 |
+
|
| 920 |
+
auto instance_norm = getObservedQParamOpFusionInfo(
|
| 921 |
+
"aten::instance_norm",
|
| 922 |
+
"quantized::instance_norm",
|
| 923 |
+
{"%weight",
|
| 924 |
+
"%bias",
|
| 925 |
+
"%running_mean",
|
| 926 |
+
"%running_var",
|
| 927 |
+
"%use_input_stats",
|
| 928 |
+
"%momentum",
|
| 929 |
+
"%eps",
|
| 930 |
+
"%cudnn_enabled"},
|
| 931 |
+
{"%weight", "%bias", "%eps"});
|
| 932 |
+
|
| 933 |
+
return {
|
| 934 |
+
{"quantized::conv1d", std::move(conv1d), std::move(quantized_conv1d)},
|
| 935 |
+
{"quantized::conv1d_relu", std::move(conv1d_relu), quantized_conv1d_relu},
|
| 936 |
+
{"quantized::conv1d_relu",
|
| 937 |
+
std::move(conv1d_inplace_relu),
|
| 938 |
+
std::move(quantized_conv1d_relu)},
|
| 939 |
+
{"quantized::conv2d", std::move(conv2d), std::move(quantized_conv2d)},
|
| 940 |
+
{"quantized::conv2d_relu", std::move(conv2d_relu), quantized_conv2d_relu},
|
| 941 |
+
{"quantized::conv2d_relu",
|
| 942 |
+
std::move(conv2d_inplace_relu),
|
| 943 |
+
std::move(quantized_conv2d_relu)},
|
| 944 |
+
{"quantized::conv3d", std::move(conv3d), std::move(quantized_conv3d)},
|
| 945 |
+
{"quantized::conv3d_relu", std::move(conv3d_relu), quantized_conv3d_relu},
|
| 946 |
+
{"quantized::conv3d_relu",
|
| 947 |
+
std::move(conv3d_inplace_relu),
|
| 948 |
+
std::move(quantized_conv3d_relu)},
|
| 949 |
+
{"quantized::conv_transpose1d",
|
| 950 |
+
std::move(conv_transpose1d),
|
| 951 |
+
std::move(quantized_conv_transpose1d)},
|
| 952 |
+
{"quantized::conv_transpose2d",
|
| 953 |
+
std::move(conv_transpose2d),
|
| 954 |
+
std::move(quantized_conv_transpose2d)},
|
| 955 |
+
{"quantized::linear", std::move(linear), std::move(quantized_linear)},
|
| 956 |
+
{"quantized::linear_relu", std::move(linear_relu), quantized_linear_relu},
|
| 957 |
+
{"quantized::linear_relu",
|
| 958 |
+
std::move(linear_inplace_relu),
|
| 959 |
+
std::move(quantized_linear_relu)},
|
| 960 |
+
{"quantized::add_relu",
|
| 961 |
+
std::move(add_relu),
|
| 962 |
+
quantized_add_relu,
|
| 963 |
+
{aten_add_alpha_is_one}},
|
| 964 |
+
{"quantized::add_relu",
|
| 965 |
+
std::move(add_inplace_relu),
|
| 966 |
+
quantized_add_relu,
|
| 967 |
+
{aten_add_alpha_is_one}},
|
| 968 |
+
{"quantized::add_relu",
|
| 969 |
+
std::move(inplace_add_relu),
|
| 970 |
+
quantized_add_relu,
|
| 971 |
+
{aten_add_alpha_is_one}},
|
| 972 |
+
{"quantized::add_relu",
|
| 973 |
+
std::move(inplace_add_inplace_relu),
|
| 974 |
+
std::move(quantized_add_relu),
|
| 975 |
+
{aten_add_alpha_is_one}},
|
| 976 |
+
std::move(add_scalar),
|
| 977 |
+
std::move(add_scalar_out),
|
| 978 |
+
// note that these must come after quantized::add_scalar and
|
| 979 |
+
// quantized::add_scalar_out patterns
|
| 980 |
+
{"quantized::add_scalar_relu",
|
| 981 |
+
quantized_add_scalar_relu_pattern,
|
| 982 |
+
quantized_add_scalar_relu_replacement},
|
| 983 |
+
{"quantized::add_scalar_relu",
|
| 984 |
+
quantized_add_scalar_inplace_relu_pattern,
|
| 985 |
+
quantized_add_scalar_relu_replacement},
|
| 986 |
+
{"quantized::add_scalar_relu_out",
|
| 987 |
+
quantized_add_scalar_relu_out_pattern,
|
| 988 |
+
quantized_add_scalar_relu_out_replacement},
|
| 989 |
+
{"quantized::add_scalar_relu_out",
|
| 990 |
+
quantized_add_scalar_inplace_relu_out_pattern,
|
| 991 |
+
quantized_add_scalar_relu_out_replacement},
|
| 992 |
+
{"quantized::add",
|
| 993 |
+
std::move(add),
|
| 994 |
+
quantized_add,
|
| 995 |
+
{aten_add_alpha_is_one}},
|
| 996 |
+
{"quantized::add",
|
| 997 |
+
std::move(inplace_add),
|
| 998 |
+
std::move(quantized_add),
|
| 999 |
+
{aten_add_alpha_is_one}},
|
| 1000 |
+
{"quantized::cat", std::move(cat), std::move(quantized_cat)},
|
| 1001 |
+
{"quantized::batch_norm",
|
| 1002 |
+
std::move(batch_norm),
|
| 1003 |
+
std::move(quantized_batch_norm)},
|
| 1004 |
+
{"quantized::batch_norm_relu",
|
| 1005 |
+
std::move(batch_norm_relu),
|
| 1006 |
+
quantized_batch_norm_relu},
|
| 1007 |
+
{"quantized::batch_norm_relu",
|
| 1008 |
+
std::move(batch_norm_inplace_relu),
|
| 1009 |
+
std::move(quantized_batch_norm_relu)},
|
| 1010 |
+
std::move(mul_scalar),
|
| 1011 |
+
std::move(mul_scalar_out),
|
| 1012 |
+
// note that these must come after quantized::mul_scalar and
|
| 1013 |
+
// quantized::mul_scalar_out patterns
|
| 1014 |
+
{"quantized::mul_scalar_relu",
|
| 1015 |
+
quantized_mul_scalar_relu_pattern,
|
| 1016 |
+
quantized_mul_scalar_relu_replacement},
|
| 1017 |
+
{"quantized::mul_scalar_relu",
|
| 1018 |
+
quantized_mul_scalar_inplace_relu_pattern,
|
| 1019 |
+
quantized_mul_scalar_relu_replacement},
|
| 1020 |
+
{"quantized::mul_scalar_relu_out",
|
| 1021 |
+
quantized_mul_scalar_relu_out_pattern,
|
| 1022 |
+
quantized_mul_scalar_relu_out_replacement},
|
| 1023 |
+
{"quantized::mul_scalar_relu_out",
|
| 1024 |
+
quantized_mul_scalar_inplace_relu_out_pattern,
|
| 1025 |
+
quantized_mul_scalar_relu_out_replacement},
|
| 1026 |
+
{"quantized::mul_relu", std::move(mul_relu), quantized_mul_relu},
|
| 1027 |
+
{"quantized::mul_relu", std::move(mul_inplace_relu), quantized_mul_relu},
|
| 1028 |
+
{"quantized::mul_relu", std::move(inplace_mul_relu), quantized_mul_relu},
|
| 1029 |
+
{"quantized::mul_relu",
|
| 1030 |
+
std::move(inplace_mul_inplace_relu),
|
| 1031 |
+
std::move(quantized_mul_relu)},
|
| 1032 |
+
{"quantized::mul", std::move(mul), quantized_mul},
|
| 1033 |
+
{"quantized::mul", std::move(inplace_mul), std::move(quantized_mul)},
|
| 1034 |
+
std::move(hardswish),
|
| 1035 |
+
std::move(hardswish_),
|
| 1036 |
+
std::move(layer_norm),
|
| 1037 |
+
std::move(group_norm),
|
| 1038 |
+
std::move(instance_norm),
|
| 1039 |
+
{"quantized::elu", std::move(elu), quantized_elu},
|
| 1040 |
+
{"quantized::elu_", std::move(elu_), std::move(quantized_elu)},
|
| 1041 |
+
std::move(avg_pool1d),
|
| 1042 |
+
std::move(avg_pool2d),
|
| 1043 |
+
std::move(avg_pool3d),
|
| 1044 |
+
std::move(adaptive_avg_pool1d),
|
| 1045 |
+
std::move(adaptive_avg_pool2d),
|
| 1046 |
+
std::move(adaptive_avg_pool3d),
|
| 1047 |
+
std::move(mean1),
|
| 1048 |
+
std::move(mean2),
|
| 1049 |
+
std::move(upsample_nearest1d),
|
| 1050 |
+
std::move(upsample_nearest2d),
|
| 1051 |
+
std::move(upsample_nearest3d),
|
| 1052 |
+
std::move(upsample_linear1d),
|
| 1053 |
+
std::move(upsample_bilinear2d),
|
| 1054 |
+
std::move(upsample_trilinear3d),
|
| 1055 |
+
std::move(upsample_nearest1d_vec),
|
| 1056 |
+
std::move(upsample_nearest2d_vec),
|
| 1057 |
+
std::move(upsample_nearest3d_vec),
|
| 1058 |
+
std::move(upsample_linear1d_vec),
|
| 1059 |
+
std::move(upsample_bilinear2d_vec),
|
| 1060 |
+
std::move(upsample_trilinear3d_vec),
|
| 1061 |
+
std::move(clamp),
|
| 1062 |
+
std::move(hardtanh),
|
| 1063 |
+
std::move(hardtanh_),
|
| 1064 |
+
std::move(leaky_relu),
|
| 1065 |
+
std::move(leaky_relu_),
|
| 1066 |
+
// fixed qparam ops
|
| 1067 |
+
std::move(hardsigmoid),
|
| 1068 |
+
std::move(hardsigmoid_),
|
| 1069 |
+
std::move(sigmoid),
|
| 1070 |
+
std::move(sigmoid_),
|
| 1071 |
+
std::move(tanh),
|
| 1072 |
+
std::move(tanh_),
|
| 1073 |
+
};
|
| 1074 |
+
}
|
| 1075 |
+
|
| 1076 |
+
inline std::vector<QuantFusionInfo>
|
| 1077 |
+
dynamic_quantized_linear_pattern_and_replacements() {
|
| 1078 |
+
std::string linear_dynamic = R"(
|
| 1079 |
+
graph(%packed_params, %a):
|
| 1080 |
+
%w_quant : Tensor, %b : Tensor? = quantized::linear_unpack(%packed_params)
|
| 1081 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1082 |
+
%r = aten::linear(%a, %w_dequant, %b)
|
| 1083 |
+
return (%r) )";
|
| 1084 |
+
|
| 1085 |
+
// This pattern ignores reduce range
|
| 1086 |
+
// Set the reduce range to default to true, since qnnpack backend ignores this
|
| 1087 |
+
// argument.
|
| 1088 |
+
std::string quantized_linear_dynamic = R"(
|
| 1089 |
+
graph(%packed_params, %a):
|
| 1090 |
+
%reduce_range : bool = prim::Constant[value=1]()
|
| 1091 |
+
%r = quantized::linear_dynamic(%a, %packed_params, %reduce_range)
|
| 1092 |
+
return (%r) )";
|
| 1093 |
+
|
| 1094 |
+
return {
|
| 1095 |
+
{"quantized::linear_dynamic",
|
| 1096 |
+
std::move(linear_dynamic),
|
| 1097 |
+
std::move(quantized_linear_dynamic)},
|
| 1098 |
+
};
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
static std::vector<QuantFusionInfo>
|
| 1102 |
+
dynamic_quant_fusion_pattern_and_replacements() {
|
| 1103 |
+
std::string linear_dynamic = R"(
|
| 1104 |
+
graph(%packed_params, %a, %reduce_range, %a_dtype):
|
| 1105 |
+
%a_scale : float, %a_zero_point : int = aten::_choose_qparams_per_tensor(%a, %reduce_range)
|
| 1106 |
+
%a_quant = aten::quantize_per_tensor(%a, %a_scale, %a_zero_point, %a_dtype)
|
| 1107 |
+
%a_dequant = aten::dequantize(%a_quant)
|
| 1108 |
+
%w_quant : Tensor, %b : Tensor? = quantized::linear_unpack(%packed_params)
|
| 1109 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1110 |
+
%r = aten::linear(%a_dequant, %w_dequant, %b)
|
| 1111 |
+
return (%r) )";
|
| 1112 |
+
|
| 1113 |
+
std::string quantized_linear_dynamic = R"(
|
| 1114 |
+
graph(%packed_params, %a, %reduce_range, %a_dtype):
|
| 1115 |
+
%r = quantized::linear_dynamic(%a, %packed_params, %reduce_range)
|
| 1116 |
+
return (%r) )";
|
| 1117 |
+
|
| 1118 |
+
std::string linear_dynamic_fp16 = R"(
|
| 1119 |
+
graph(%packed_params, %a):
|
| 1120 |
+
%w_unpacked : Tensor, %b : Tensor? = quantized::linear_unpack_fp16(%packed_params)
|
| 1121 |
+
%r = aten::linear(%a, %w_unpacked, %b)
|
| 1122 |
+
return (%r) )";
|
| 1123 |
+
|
| 1124 |
+
std::string quantized_linear_dynamic_fp16 = R"(
|
| 1125 |
+
graph(%packed_params, %a):
|
| 1126 |
+
%r = quantized::linear_dynamic_fp16(%a, %packed_params)
|
| 1127 |
+
return (%r) )";
|
| 1128 |
+
|
| 1129 |
+
return {
|
| 1130 |
+
{"quantized::linear_dynamic",
|
| 1131 |
+
std::move(linear_dynamic),
|
| 1132 |
+
std::move(quantized_linear_dynamic)},
|
| 1133 |
+
{"quantized::linear_dynamic_fp16",
|
| 1134 |
+
std::move(linear_dynamic_fp16),
|
| 1135 |
+
std::move(quantized_linear_dynamic_fp16)},
|
| 1136 |
+
};
|
| 1137 |
+
}
|
| 1138 |
+
|
| 1139 |
+
static std::vector<QuantFusionInfo> linear_prepack_unpack_patterns() {
|
| 1140 |
+
std::string linear_with_quant = R"(
|
| 1141 |
+
graph(%a_dequant, %w_quant, %b):
|
| 1142 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1143 |
+
%r = aten::linear(%a_dequant, %w_dequant, %b)
|
| 1144 |
+
return (%r) )";
|
| 1145 |
+
|
| 1146 |
+
std::string linear_with_quant_prepack = R"(
|
| 1147 |
+
graph(%a_dequant, %w_quant, %b):
|
| 1148 |
+
%packed_params = quantized::linear_prepack(%w_quant, %b)
|
| 1149 |
+
%w_quant_unpacked : Tensor, %b_unpacked : Tensor? = quantized::linear_unpack(%packed_params)
|
| 1150 |
+
%w_dequant = aten::dequantize(%w_quant_unpacked)
|
| 1151 |
+
%r = aten::linear(%a_dequant, %w_dequant, %b_unpacked)
|
| 1152 |
+
return (%r) )";
|
| 1153 |
+
std::string linear_fp16_with_cast = R"(
|
| 1154 |
+
graph(%w, %a_dq, %b):
|
| 1155 |
+
%fp16_tensor = aten::_saturate_weight_to_fp16(%w)
|
| 1156 |
+
%r = aten::linear(%a_dq, %fp16_tensor, %b)
|
| 1157 |
+
return (%r) )";
|
| 1158 |
+
std::string linear_fp16_with_prepack = R"(
|
| 1159 |
+
graph(%w, %a_dq, %b):
|
| 1160 |
+
%packed_params = quantized::linear_prepack_fp16(%w, %b)
|
| 1161 |
+
%w_unpacked : Tensor, %b_unpacked : Tensor? = quantized::linear_unpack_fp16(%packed_params)
|
| 1162 |
+
%r = aten::linear(%a_dq, %w_unpacked, %b_unpacked)
|
| 1163 |
+
return (%r) )";
|
| 1164 |
+
|
| 1165 |
+
return {
|
| 1166 |
+
{"linear_prepack_unpack",
|
| 1167 |
+
std::move(linear_with_quant),
|
| 1168 |
+
std::move(linear_with_quant_prepack)},
|
| 1169 |
+
{"linear_fp16_prepack_unpack",
|
| 1170 |
+
std::move(linear_fp16_with_cast),
|
| 1171 |
+
std::move(linear_fp16_with_prepack)},
|
| 1172 |
+
};
|
| 1173 |
+
}
|
| 1174 |
+
|
| 1175 |
+
static std::vector<QuantFusionInfo> conv_prepack_unpack_patterns() {
|
| 1176 |
+
std::string conv1d_with_quant = R"(
|
| 1177 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %dilation, %groups):
|
| 1178 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1179 |
+
%r = aten::conv1d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 1180 |
+
return (%r) )";
|
| 1181 |
+
|
| 1182 |
+
std::string conv1d_with_quant_prepack = R"(
|
| 1183 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %dilation, %groups):
|
| 1184 |
+
%packed_params : __torch__.torch.classes.quantized.Conv2dPackedParamsBase = quantized::conv1d_prepack(%w_quant, %b, %stride, %padding, %dilation, %groups)
|
| 1185 |
+
%w_quant_unpacked : Tensor, %b_unpacked : Tensor? = quantized::conv1d_unpack(%packed_params)
|
| 1186 |
+
%w_dequant = aten::dequantize(%w_quant_unpacked)
|
| 1187 |
+
%r = aten::conv1d(%a_dequant, %w_dequant, %b_unpacked, %stride, %padding, %dilation, %groups)
|
| 1188 |
+
return (%r) )";
|
| 1189 |
+
|
| 1190 |
+
std::string conv2d_with_quant = R"(
|
| 1191 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %dilation, %groups):
|
| 1192 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1193 |
+
%r = aten::conv2d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 1194 |
+
return (%r) )";
|
| 1195 |
+
|
| 1196 |
+
std::string conv2d_with_quant_prepack = R"(
|
| 1197 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %dilation, %groups):
|
| 1198 |
+
%packed_params : __torch__.torch.classes.quantized.Conv2dPackedParamsBase = quantized::conv2d_prepack(%w_quant, %b, %stride, %padding, %dilation, %groups)
|
| 1199 |
+
%w_quant_unpacked : Tensor, %b_unpacked : Tensor? = quantized::conv2d_unpack(%packed_params)
|
| 1200 |
+
%w_dequant = aten::dequantize(%w_quant_unpacked)
|
| 1201 |
+
%r = aten::conv2d(%a_dequant, %w_dequant, %b_unpacked, %stride, %padding, %dilation, %groups)
|
| 1202 |
+
return (%r) )";
|
| 1203 |
+
|
| 1204 |
+
std::string conv3d_with_quant = R"(
|
| 1205 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %dilation, %groups):
|
| 1206 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1207 |
+
%r = aten::conv3d(%a_dequant, %w_dequant, %b, %stride, %padding, %dilation, %groups)
|
| 1208 |
+
return (%r) )";
|
| 1209 |
+
|
| 1210 |
+
std::string conv3d_with_quant_prepack = R"(
|
| 1211 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %dilation, %groups):
|
| 1212 |
+
%packed_params : __torch__.torch.classes.quantized.Conv3dPackedParamsBase = quantized::conv3d_prepack(%w_quant, %b, %stride, %padding, %dilation, %groups)
|
| 1213 |
+
%w_quant_unpacked : Tensor, %b_unpacked : Tensor? = quantized::conv3d_unpack(%packed_params)
|
| 1214 |
+
%w_dequant = aten::dequantize(%w_quant_unpacked)
|
| 1215 |
+
%r = aten::conv3d(%a_dequant, %w_dequant, %b_unpacked, %stride, %padding, %dilation, %groups)
|
| 1216 |
+
return (%r) )";
|
| 1217 |
+
|
| 1218 |
+
std::string conv_transpose1d_with_quant = R"(
|
| 1219 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %output_padding, %groups, %dilation):
|
| 1220 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1221 |
+
%r = aten::conv_transpose1d(%a_dequant, %w_dequant, %b, %stride, %padding, %output_padding, %groups, %dilation)
|
| 1222 |
+
return (%r) )";
|
| 1223 |
+
|
| 1224 |
+
std::string conv_transpose1d_with_quant_prepack = R"(
|
| 1225 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %output_padding, %groups, %dilation):
|
| 1226 |
+
%packed_params : __torch__.torch.classes.quantized.Conv2dPackedParamsBase = quantized::conv_transpose1d_prepack(%w_quant, %b, %stride, %padding, %output_padding, %dilation, %groups)
|
| 1227 |
+
%w_quant_unpacked : Tensor, %b_unpacked : Tensor? = quantized::conv_transpose1d_unpack(%packed_params)
|
| 1228 |
+
%w_dequant = aten::dequantize(%w_quant_unpacked)
|
| 1229 |
+
%r = aten::conv_transpose1d(%a_dequant, %w_dequant, %b_unpacked, %stride, %padding, %output_padding, %groups, %dilation)
|
| 1230 |
+
return (%r) )";
|
| 1231 |
+
|
| 1232 |
+
std::string conv_transpose2d_with_quant = R"(
|
| 1233 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %output_padding, %groups, %dilation):
|
| 1234 |
+
%w_dequant = aten::dequantize(%w_quant)
|
| 1235 |
+
%r = aten::conv_transpose2d(%a_dequant, %w_dequant, %b, %stride, %padding, %output_padding, %groups, %dilation)
|
| 1236 |
+
return (%r) )";
|
| 1237 |
+
|
| 1238 |
+
std::string conv_transpose2d_with_quant_prepack = R"(
|
| 1239 |
+
graph(%a_dequant, %w_quant, %b, %stride, %padding, %output_padding, %groups, %dilation):
|
| 1240 |
+
%packed_params : __torch__.torch.classes.quantized.Conv2dPackedParamsBase = quantized::conv_transpose2d_prepack(%w_quant, %b, %stride, %padding, %output_padding, %dilation, %groups)
|
| 1241 |
+
%w_quant_unpacked : Tensor, %b_unpacked : Tensor? = quantized::conv_transpose2d_unpack(%packed_params)
|
| 1242 |
+
%w_dequant = aten::dequantize(%w_quant_unpacked)
|
| 1243 |
+
%r = aten::conv_transpose2d(%a_dequant, %w_dequant, %b_unpacked, %stride, %padding, %output_padding, %groups, %dilation)
|
| 1244 |
+
return (%r) )";
|
| 1245 |
+
|
| 1246 |
+
return {
|
| 1247 |
+
{"conv1d_prepack_unpack",
|
| 1248 |
+
std::move(conv1d_with_quant),
|
| 1249 |
+
std::move(conv1d_with_quant_prepack)},
|
| 1250 |
+
{"conv2d_prepack_unpack",
|
| 1251 |
+
std::move(conv2d_with_quant),
|
| 1252 |
+
std::move(conv2d_with_quant_prepack)},
|
| 1253 |
+
{"conv3d_prepack_unpack",
|
| 1254 |
+
std::move(conv3d_with_quant),
|
| 1255 |
+
std::move(conv3d_with_quant_prepack)},
|
| 1256 |
+
{"conv_transpose1d_prepack_unpack",
|
| 1257 |
+
std::move(conv_transpose1d_with_quant),
|
| 1258 |
+
std::move(conv_transpose1d_with_quant_prepack)},
|
| 1259 |
+
{"conv_transpose2d_prepack_unpack",
|
| 1260 |
+
std::move(conv_transpose2d_with_quant),
|
| 1261 |
+
std::move(conv_transpose2d_with_quant_prepack)}};
|
| 1262 |
+
}
|
| 1263 |
+
|
| 1264 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/quantization_type.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <cstdint>
|
| 3 |
+
#include <ostream>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// Quantization type (dynamic quantization, static quantization).
|
| 8 |
+
// Should match the Python enum in quantize_jit.py
|
| 9 |
+
enum QuantType : std::uint8_t { DYNAMIC = 0, STATIC };
|
| 10 |
+
|
| 11 |
+
std::ostream& operator<<(std::ostream& os, QuantType t);
|
| 12 |
+
|
| 13 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/quantization/register_packed_params.h
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
#include <memory>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit {
|
| 8 |
+
|
| 9 |
+
using PrePackParamFilterFn = std::function<bool(Node*)>;
|
| 10 |
+
|
| 11 |
+
TORCH_API std::unordered_set<std::string> RegisterPrePackParams(
|
| 12 |
+
Module& m,
|
| 13 |
+
const std::string& method_name,
|
| 14 |
+
const PrePackParamFilterFn& is_packed_param,
|
| 15 |
+
const std::string& attr_prefix);
|
| 16 |
+
|
| 17 |
+
TORCH_API std::string joinPaths(const std::vector<std::string>& paths);
|
| 18 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/refine_tuple_types.h
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit {
|
| 6 |
+
|
| 7 |
+
// updates the types of tuples according to the type of their current inputs.
|
| 8 |
+
TORCH_API void RefineTupleTypes(std::shared_ptr<Graph>& graph);
|
| 9 |
+
|
| 10 |
+
} // namespace torch::jit
|
tool_server/.venv/lib/python3.12/site-packages/torch/include/torch/csrc/jit/passes/remove_dropout.h
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/api/module.h>
|
| 4 |
+
#include <torch/csrc/jit/ir/ir.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::jit {
|
| 7 |
+
|
| 8 |
+
TORCH_API void removeDropout(std::shared_ptr<Graph>& graph);
|
| 9 |
+
|
| 10 |
+
TORCH_API void removeDropout(script::Module& module);
|
| 11 |
+
|
| 12 |
+
} // namespace torch::jit
|