onnxruntime/onnxruntime
Zhipeng Han a55b2688b6
Add save_attribute option to quantize_static (#17945)
### Description
<!-- Describe your changes. -->
The model with big Constants tensors size: Estimate size of the RWKV
model: ONNX graph (8MB), initializer tensors(200MB), constants (~5.7GB).
The `onnx.save_model` will got error due to the Constants is not output
in external data. Only the initializer tensors are output as external
data. In this change, expose parameter to support the constants in
external data. Model owner can customize the output behavior and still
keep the default behavior.

Quantize the model and output it to local, got issue due to output size
exceed 2GB even set `use_external_data_format=True`. The
`use_external_data_format` flag only outputs initializer tensors to
external data.
Use the falg `convert_attribute` flag to output all tensors to external
data.
```
def convert_model_to_external_data(
    model: ModelProto,
    all_tensors_to_one_file: bool = True,
    location: Optional[str] = None,
    size_threshold: int = 1024,
    include_attribute: bool = False,
) -> None:
    tensors = _get_initializer_tensors(model)
    if include_attribute:
        tensors = _get_all_tensors(model)
        ...
```
The `onnx.external_data_helper.convert_model_to_external_data` support
output the attribute to external with flag `include_attribute=True`.
However, this parameter is hide by the
`onnxruntime\quantization\onnx_model.py` and the constants(`5.7GB)
within the model will got protobuf 2GB limitation issue with default
parameters.


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Fix https://github.com/microsoft/onnxruntime/issues/17944

---------

Co-authored-by: Thiago Crepaldi <thiago.crepaldi@microsoft.com>
2023-10-14 06:29:08 -07:00
..
contrib_ops Add MatMul 4bits support on GPU (#17890) 2023-10-13 16:55:30 -07:00
core Add MatMul 4bits support on GPU (#17890) 2023-10-13 16:55:30 -07:00
python Add save_attribute option to quantize_static (#17945) 2023-10-14 06:29:08 -07:00
test Add MatMul 4bits support on GPU (#17890) 2023-10-13 16:55:30 -07:00
tool/etw Run clang-format in CI (#15524) 2023-04-18 09:26:58 -07:00
wasm [js/webgpu] support IO binding (#17480) 2023-09-29 11:24:42 -07:00
__init__.py Python API to check whether collective ops are available or not (#17730) 2023-09-29 14:11:05 -07:00
ReformatSource.ps1 Run clang-format in CI (#15524) 2023-04-18 09:26:58 -07:00
ReformatSourcePython.bat
VSCodeCoverage.runsettings