diff --git a/.github/workflows/linux-wasm-ci-build-and-test-workflow.yml b/.github/workflows/linux-wasm-ci-build-and-test-workflow.yml index e08ce13c6dd33..4288442720493 100644 --- a/.github/workflows/linux-wasm-ci-build-and-test-workflow.yml +++ b/.github/workflows/linux-wasm-ci-build-and-test-workflow.yml @@ -50,6 +50,12 @@ jobs: --enable_wasm_simd ${{ inputs.enable_wasm_threads == true && '--enable_wasm_threads' || '' }} ${{ inputs.extra_build_args }} + reduced_size_build_args: >- + --disable_ml_ops + --disable_generation_ops + --disable_types string float4 float8 optional sparsetensor + --include_ops_by_config onnxruntime/wasm/reduced_types.config + --enable_reduced_operator_type_support steps: - name: Checkout code @@ -68,6 +74,9 @@ jobs: python-version: "3.12" architecture: ${{ env.buildArch }} + - name: Install python dependencies + run: python -m pip install flatbuffers + - uses: microsoft/onnxruntime-github-actions/setup-build-tools@v0.0.9 with: vcpkg-version: '2025.08.27' @@ -109,6 +118,7 @@ jobs: --use_webnn \ --target onnxruntime_webassembly \ ${{ inputs.build_config == 'Release' && '--enable_wasm_api_exception_catching' || '' }} \ + ${{ env.reduced_size_build_args }} \ --skip_tests working-directory: ${{ github.workspace }} @@ -122,6 +132,7 @@ jobs: --use_webnn \ --enable_wasm_jspi \ --target onnxruntime_webassembly \ + ${{ env.reduced_size_build_args }} \ --skip_tests working-directory: ${{ github.workspace }} diff --git a/js/build_jsep.bat b/js/build_jsep.bat index ace96e978d934..fb94f0841ee01 100644 --- a/js/build_jsep.bat +++ b/js/build_jsep.bat @@ -64,8 +64,21 @@ popd set PATH=C:\Program Files\Git\usr\bin;%PATH% -call %ROOT%build.bat --config %CONFIG% %CONFIG_EXTRA_FLAG% --skip_submodule_sync --build_wasm --skip_tests^ - --enable_wasm_simd --enable_wasm_threads --use_jsep --use_webnn --target onnxruntime_webassembly --build_dir %BUILD_DIR% +call %ROOT%build.bat^ + --config %CONFIG%^ + %CONFIG_EXTRA_FLAG%^ + --parallel^ + --skip_submodule_sync^ + --build_wasm^ + --target onnxruntime_webassembly^ + --skip_tests^ + --enable_wasm_simd^ + --enable_wasm_threads^ + --use_jsep^ + --use_webnn^ + --build_dir %BUILD_DIR%^ + --include_ops_by_config %ROOT%onnxruntime\wasm\reduced_types.config^ + --enable_reduced_operator_type_support IF NOT "%ERRORLEVEL%" == "0" ( exit /b %ERRORLEVEL% diff --git a/js/build_webgpu.bat b/js/build_webgpu.bat index d32a7ab1abb81..5d017edbfa22b 100644 --- a/js/build_webgpu.bat +++ b/js/build_webgpu.bat @@ -68,8 +68,22 @@ popd set PATH=C:\Program Files\Git\usr\bin;%PATH% -call %ROOT%build.bat --config %CONFIG% %CONFIG_EXTRA_FLAG% --skip_submodule_sync --build_wasm --target onnxruntime_webassembly --skip_tests^ - --enable_wasm_simd --enable_wasm_threads --use_webnn --use_webgpu --enable_wasm_jspi --build_dir %BUILD_DIR% +call %ROOT%build.bat^ + --config %CONFIG%^ + %CONFIG_EXTRA_FLAG%^ + --parallel^ + --skip_submodule_sync^ + --build_wasm^ + --target onnxruntime_webassembly^ + --skip_tests^ + --enable_wasm_simd^ + --enable_wasm_threads^ + --use_webnn^ + --use_webgpu^ + --enable_wasm_jspi^ + --build_dir %BUILD_DIR%^ + --include_ops_by_config %ROOT%onnxruntime\wasm\reduced_types.config^ + --enable_reduced_operator_type_support IF NOT "%ERRORLEVEL%" == "0" ( exit /b %ERRORLEVEL% diff --git a/js/build_webgpu.sh b/js/build_webgpu.sh index ea12093c37cf7..1e9492d818680 100755 --- a/js/build_webgpu.sh +++ b/js/build_webgpu.sh @@ -101,7 +101,9 @@ echo "Calling $ROOT_DIR/build.sh to build WebAssembly..." --use_webnn \ --use_webgpu \ --enable_wasm_jspi \ - --build_dir "$BUILD_DIR" + --build_dir "$BUILD_DIR" \ + --include_ops_by_config "$ROOT_DIR/onnxruntime/wasm/reduced_types.config" \ + --enable_reduced_operator_type_support # The 'set -e' command at the beginning of the script ensures that the script will exit # immediately if the build.sh command (or any other command) fails. diff --git a/onnxruntime/wasm/reduced_types.config b/onnxruntime/wasm/reduced_types.config new file mode 100644 index 0000000000000..5e5ced7e759f4 --- /dev/null +++ b/onnxruntime/wasm/reduced_types.config @@ -0,0 +1,14 @@ +# Reduced type configuration for WebAssembly builds. +# This limits globally allowed types for all operators to reduce binary size (~230KB). +# See https://onnxruntime.ai/docs/reference/operators/reduced-operator-config-file.html +# +# Usage: pass to build.py via: +# --include_ops_by_config onnxruntime/wasm/reduced_types.config --enable_reduced_operator_type_support +# +# Excluded types: float4, float8, float64 (double), int16, uint16 + +# Keep all operators - only apply type reduction +!no_ops_specified_means_all_ops_are_required + +# Globally allowed types for all operators +!globally_allowed_types;bool,int8_t,uint8_t,int32_t,uint32_t,int64_t,uint64_t,float,MLFloat16 diff --git a/tools/ci_build/github/azure-pipelines/templates/linux-wasm-ci.yml b/tools/ci_build/github/azure-pipelines/templates/linux-wasm-ci.yml index ef30a49b0fb83..97e7a43a88824 100644 --- a/tools/ci_build/github/azure-pipelines/templates/linux-wasm-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/linux-wasm-ci.yml @@ -57,6 +57,7 @@ jobs: ExceptionHandlingBuildArgs: '--enable_wasm_api_exception_catching' ${{ else }}: ExceptionHandlingBuildArgs: '' + reducedSizeBuildArgs: '--disable_ml_ops --disable_generation_ops --disable_types string float4 float8 optional sparsetensor --include_ops_by_config $(Build.SourcesDirectory)/onnxruntime/wasm/reduced_types.config --enable_reduced_operator_type_support' runCodesignValidationInjection: false TODAY: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)] ORT_CACHE_DIR: $(Agent.TempDirectory)/ort_ccache @@ -92,6 +93,9 @@ jobs: inputs: versionSpec: '22.x' + - script: python -m pip install flatbuffers + displayName: 'Install python dependencies' + - ${{if eq(parameters.WithCache, true)}}: - script: | set -ex @@ -141,7 +145,7 @@ jobs: ${{ else }}: AdditionalKey: wasm_inferencing_webgpu | ${{ parameters.BuildConfig }} CacheDir: $(ORT_CACHE_DIR)/wasm_inferencing_webgpu - Arguments: '$(CommonBuildArgs) --build_dir $(Build.BinariesDirectory)/wasm_inferencing_webgpu --use_webgpu --use_webnn --target onnxruntime_webassembly $(ExceptionHandlingBuildArgs) --skip_tests' + Arguments: '$(CommonBuildArgs) --build_dir $(Build.BinariesDirectory)/wasm_inferencing_webgpu --use_webgpu --use_webnn --target onnxruntime_webassembly $(ExceptionHandlingBuildArgs) $(reducedSizeBuildArgs) --skip_tests' DisplayName: 'Build (simd + threads + WebGPU experimental)' WithCache: ${{ parameters.WithCache }} @@ -154,7 +158,7 @@ jobs: ${{ else }}: AdditionalKey: wasm_inferencing_webgpu_jspi | ${{ parameters.BuildConfig }} CacheDir: $(ORT_CACHE_DIR)/wasm_inferencing_webgpu_jspi - Arguments: '$(CommonBuildArgs) --build_dir $(Build.BinariesDirectory)/wasm_inferencing_webgpu_jspi --use_webgpu --use_webnn --enable_wasm_jspi --target onnxruntime_webassembly --skip_tests' + Arguments: '$(CommonBuildArgs) --build_dir $(Build.BinariesDirectory)/wasm_inferencing_webgpu_jspi --use_webgpu --use_webnn --enable_wasm_jspi --target onnxruntime_webassembly $(reducedSizeBuildArgs) --skip_tests' DisplayName: 'Build (simd + threads + WebGPU experimental, JSPI)' WithCache: ${{ parameters.WithCache }}