Skip to content

Commit b999a1b

Browse files
Merge pull request #643 from intel/syncing_msft_8_4_25
Backmerging with Msft commits
2 parents c0c347c + 8517c64 commit b999a1b

File tree

106 files changed

+3187
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+3187
-540
lines changed

.github/actions/webgpu-validate-shader-key/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ runs:
2222
working-directory: ${{ github.action_path }}
2323

2424
- name: Validate shader keys (native log)
25-
if: ${{ !inputs.is_chromium_log != 'true' }}
25+
if: ${{ inputs.is_chromium_log != 'true' }}
2626
shell: cmd
2727
run: |
2828
node validate-shader-key.js < "${{ inputs.log_file_path }}"

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
level: info
2727
filter_mode: diff_context
2828
- name: shellcheck # Static check shell scripts
29-
uses: reviewdog/action-shellcheck@v1
29+
uses: reviewdog/action-shellcheck@v1.30.0
3030
with:
3131
github_token: ${{ secrets.github_token }}
3232
reporter: github-pr-check

.github/workflows/windows-web-ci-workflow.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ jobs:
200200

201201
- name: Validate shader keys - WebGPU EP
202202
if: ${{ inputs.run_webgpu_tests == true && inputs.build_config == 'Debug' }}
203-
continue-on-error: true
204203
uses: ./.github/actions/webgpu-validate-shader-key
205204
with:
206205
log_file_path: ${{ runner.temp }}\web\test\07\chrome_debug.log

.github/workflows/windows_webgpu.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ jobs:
126126
dir ${{ github.workspace }}\RelWithDebInfo\RelWithDebInfo\onnxruntime_test_all_stderr.log
127127
128128
- name: Validate shader keys
129-
continue-on-error: true
130129
uses: ./.github/actions/webgpu-validate-shader-key
131130
with:
132131
log_file_path: ${{ github.workspace }}\RelWithDebInfo\RelWithDebInfo\onnxruntime_test_all_stderr.log

csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Runtime.InteropServices;
6+
using static Microsoft.ML.OnnxRuntime.NativeMethods;
67

78
namespace Microsoft.ML.OnnxRuntime
89
{
@@ -325,6 +326,16 @@ public struct OrtApi
325326
public IntPtr CreateLoraAdapterFromArray;
326327
public IntPtr ReleaseLoraAdapter;
327328
public IntPtr RunOptionsAddActiveLoraAdapter;
329+
public IntPtr SetEpDynamicOptions;
330+
public IntPtr ReleaseValueInfo;
331+
public IntPtr ReleaseNode;
332+
public IntPtr ReleaseGraph;
333+
public IntPtr ReleaseModel;
334+
public IntPtr GetValueInfoName;
335+
public IntPtr GetValueInfoTypeInfo;
336+
public IntPtr GetModelEditorApi;
337+
public IntPtr CreateTensorWithDataAndDeleterAsOrtValue;
338+
public IntPtr SessionOptionsSetLoadCancellationFlag;
328339
}
329340

330341
internal static class NativeMethods
@@ -404,6 +415,7 @@ static NativeMethods()
404415
OrtReleaseSessionOptions = (DOrtReleaseSessionOptions)Marshal.GetDelegateForFunctionPointer(api_.ReleaseSessionOptions, typeof(DOrtReleaseSessionOptions));
405416
OrtCloneSessionOptions = (DOrtCloneSessionOptions)Marshal.GetDelegateForFunctionPointer(api_.CloneSessionOptions, typeof(DOrtCloneSessionOptions));
406417
OrtSetSessionExecutionMode = (DOrtSetSessionExecutionMode)Marshal.GetDelegateForFunctionPointer(api_.SetSessionExecutionMode, typeof(DOrtSetSessionExecutionMode));
418+
OrtSessionOptionsSetLoadCancellationFlag = (DOrtSessionOptionsSetLoadCancellationFlag)Marshal.GetDelegateForFunctionPointer(api_.SessionOptionsSetLoadCancellationFlag, typeof(DOrtSessionOptionsSetLoadCancellationFlag));
407419
OrtSetOptimizedModelFilePath = (DOrtSetOptimizedModelFilePath)Marshal.GetDelegateForFunctionPointer(api_.SetOptimizedModelFilePath, typeof(DOrtSetOptimizedModelFilePath));
408420
OrtEnableProfiling = (DOrtEnableProfiling)Marshal.GetDelegateForFunctionPointer(api_.EnableProfiling, typeof(DOrtEnableProfiling));
409421
OrtDisableProfiling = (DOrtDisableProfiling)Marshal.GetDelegateForFunctionPointer(api_.DisableProfiling, typeof(DOrtDisableProfiling));
@@ -1025,6 +1037,12 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
10251037
ExecutionMode execution_mode);
10261038
public static DOrtSetSessionExecutionMode OrtSetSessionExecutionMode;
10271039

1040+
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
1041+
public delegate IntPtr /*(OrtStatus*)*/ DOrtSessionOptionsSetLoadCancellationFlag(IntPtr /*(OrtSessionOptions*)*/ options,
1042+
bool value);
1043+
public static DOrtSessionOptionsSetLoadCancellationFlag OrtSessionOptionsSetLoadCancellationFlag;
1044+
1045+
10281046
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
10291047
public delegate IntPtr /*(OrtStatus*)*/ DOrtSetOptimizedModelFilePath(IntPtr /* OrtSessionOptions* */ options, byte[] optimizedModelFilepath);
10301048
public static DOrtSetOptimizedModelFilePath OrtSetOptimizedModelFilePath;

csharp/src/Microsoft.ML.OnnxRuntime/SessionOptions.shared.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,16 @@ public ExecutionMode ExecutionMode
802802
}
803803
private ExecutionMode _executionMode = ExecutionMode.ORT_SEQUENTIAL;
804804

805+
/// <summary>
806+
/// Sets the load cancellation flag for the session. Default is set to false.
807+
/// Provides an opportunity for the user to cancel model loading.
808+
/// </summary>
809+
/// <param name="value">true to request cancellation, false to proceed</param>
810+
public void SetLoadCancellationFlag(bool value)
811+
{
812+
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsSetLoadCancellationFlag(handle, value));
813+
}
814+
805815
#endregion
806816

807817
#region Private Methods

docs/ContribOperators.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,10 +2039,11 @@ This version of the operator has been available since version 1 of the 'com.micr
20392039
1. Input `data` is a constant. It is quantized block-wise along attribute `quantize_axis` with block size specified by attribute `block_size`.
20402040
`block_size must` be a power of 2 and not smaller than 16, like 16, 32, 64, 128, ..
20412041
2. Input `data`'s scale and zero point are specified by input `scales` and `zero_points`. `scales` and `zero_points` are also constants.
2042-
If `zero_points` is not provided, 0 is the zero point.
2042+
If `zero_points` is not provided, 0 is the zero point except when data is uint8 type then the default zero point is 8.
20432043
3. During the op execution, `data` and `indices` are first used to generate the quantized output. Then, `scales` and `zero_points` are used
20442044
to dequantize the output.
20452045
4. The `output` and `scales` have the same type. The `data` and `zero_points` have the same type.
2046+
5. For uint8 data, the `gather_axis` must be 0.
20462047

20472048
#### Version
20482049

@@ -2082,7 +2083,7 @@ This version of the operator has been available since version 1 of the 'com.micr
20822083
#### Type Constraints
20832084

20842085
<dl>
2085-
<dt><tt>T1</tt> : tensor(int4), tensor(uint4)</dt>
2086+
<dt><tt>T1</tt> : tensor(int4), tensor(uint4), tensor(uint8)</dt>
20862087
<dd>Constrain quantized types.</dd>
20872088
<dt><tt>T2</tt> : tensor(float), tensor(float16), tensor(bfloat16)</dt>
20882089
<dd>Constrain dequantized types.</dd>

docs/OperatorKernels.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ Do not modify directly.*
515515
|FusedConv|*in* X:**T**<br> *in* W:**T**<br> *in* B:**T**<br> *in* Z:**T**<br> *out* Y:**T**|1+|**T** = tensor(float)|
516516
|FusedGemm|*in* A:**T**<br> *in* B:**T**<br> *in* C:**T**<br> *out* Y:**T**|1+|**T** = tensor(float)|
517517
|FusedMatMul|*in* A:**T**<br> *in* B:**T**<br> *out* Y:**T**|1+|**T** = tensor(float)|
518-
|GatherBlockQuantized|*in* data:**T1**<br> *in* indices:**Tind**<br> *in* scales:**T2**<br> *in* zero_points:**T1**<br> *out* output:**T2**|1+|**T1** = tensor(int4), tensor(uint4)<br/> **T2** = tensor(float), tensor(float16)<br/> **Tind** = tensor(int32), tensor(int64)|
518+
|GatherBlockQuantized|*in* data:**T1**<br> *in* indices:**Tind**<br> *in* scales:**T2**<br> *in* zero_points:**T1**<br> *out* output:**T2**|1+|**T1** = tensor(int4), tensor(uint4), tensor(uint8)<br/> **T2** = tensor(float), tensor(float16)<br/> **Tind** = tensor(int32), tensor(int64)|
519519
|GatherND|*in* data:**T**<br> *in* indices:**Tind**<br> *out* output:**T**|1+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)<br/> **Tind** = tensor(int32), tensor(int64)|
520520
|Gelu|*in* X:**T**<br> *out* Y:**T**|1+|**T** = tensor(float)|
521521
|GreedySearch|*in* input_ids:**I**<br> *in* max_length:**I**<br> *in* min_length:**I**<br> *in* repetition_penalty:**T**<br> *in* vocab_mask:**I**<br> *in* prefix_vocab_mask:**I**<br> *in* attention_mask:**I**<br> *out* sequences:**I**|1+|**T** = tensor(float)|

include/onnxruntime/core/common/common.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ void LogRuntimeError(uint32_t session_id, const common::Status& status, const ch
148148
abort(); \
149149
} while (false)
150150

151+
#define ORT_THROW_FROM_STATUS(status) \
152+
do { \
153+
::onnxruntime::PrintFinalMessage( \
154+
::onnxruntime::OnnxRuntimeException( \
155+
ORT_WHERE_WITH_STACK, status.ToString()) \
156+
.what()); \
157+
abort(); \
158+
} while (false)
159+
160+
#define ORT_THROW_WITH_CATEGORY_AND_CODE(category, code, ...) \
161+
do { \
162+
::onnxruntime::PrintFinalMessage( \
163+
::onnxruntime::OnnxRuntimeException(ORT_WHERE_WITH_STACK, \
164+
::onnxruntime::MakeString(__VA_ARGS__), \
165+
::onnxruntime::common::category, \
166+
::onnxruntime::common::code) \
167+
.what()); \
168+
abort(); \
169+
} while (false)
170+
151171
#else
152172

153173
#define ORT_TRY try
@@ -180,6 +200,16 @@ void LogRuntimeError(uint32_t session_id, const common::Status& status, const ch
180200
#define ORT_THROW_EX(ex, ...) \
181201
throw ex(__VA_ARGS__)
182202

203+
#define ORT_THROW_FROM_STATUS(status) \
204+
throw ::onnxruntime::OnnxRuntimeException(ORT_WHERE_WITH_STACK, status.ToString(), status.Category(), \
205+
static_cast<::onnxruntime::common::StatusCode>(status.Code()))
206+
207+
#define ORT_THROW_WITH_CATEGORY_AND_CODE(category, code, ...) \
208+
throw ::onnxruntime::OnnxRuntimeException(ORT_WHERE_WITH_STACK, \
209+
::onnxruntime::MakeString(__VA_ARGS__), \
210+
::onnxruntime::common::category, \
211+
::onnxruntime::common::code)
212+
183213
#endif
184214

185215
#define ORT_MAKE_STATUS(category, code, ...) \
@@ -237,7 +267,7 @@ void LogRuntimeError(uint32_t session_id, const common::Status& status, const ch
237267
auto _status = (expr); \
238268
if ((!_status.IsOK())) { \
239269
::onnxruntime::LogRuntimeError(0, _status, __FILE__, static_cast<const char*>(__FUNCTION__), __LINE__); \
240-
ORT_THROW(_status); \
270+
ORT_THROW_FROM_STATUS(_status); \
241271
} \
242272
} while (0)
243273

include/onnxruntime/core/common/exceptions.h

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <vector>
1212

1313
#include "core/common/common.h"
14+
#include "core/common/status.h"
1415
#include "core/common/code_location.h"
1516

1617
namespace onnxruntime {
@@ -35,12 +36,44 @@ class OnnxRuntimeException : public std::exception {
3536
/**
3637
Create a new exception that captures the location it was thrown from.
3738
@param location Location in the source code the exception is being thrown from
39+
@param msg Message containing additional information about the exception cause.
40+
@param category Error category
41+
@param code Error code
42+
*/
43+
44+
OnnxRuntimeException(const CodeLocation& location,
45+
const std::string& message,
46+
common::StatusCategory category,
47+
common::StatusCode code) noexcept
48+
: OnnxRuntimeException(location, nullptr, message, category, code) {
49+
}
50+
51+
/**
52+
Create a new exception that captures the location it was thrown from.
53+
The instance will be created with ONNXRUNTIME category and FAIL code.
54+
@param location Location in the source code the exception is being thrown from
3855
@param failed_condition Optional string containing the condition that failed.
3956
e.g. "tensor.Size() == input.Size()". May be nullptr.
4057
@param msg Message containing additional information about the exception cause.
4158
*/
42-
OnnxRuntimeException(const CodeLocation& location, const char* failed_condition, const std::string& msg)
43-
: location_{location} {
59+
OnnxRuntimeException(const CodeLocation& location, const char* failed_condition, const std::string& msg) noexcept
60+
: OnnxRuntimeException(location, failed_condition, msg,
61+
common::StatusCategory::ONNXRUNTIME, common::StatusCode::FAIL) {
62+
}
63+
64+
/**
65+
Create a new exception that captures the location it was thrown from.
66+
@param location Location in the source code the exception is being thrown from
67+
@param failed_condition Optional string containing the condition that failed.
68+
e.g. "tensor.Size() == input.Size()". May be nullptr.
69+
@param msg Message containing additional information about the exception cause.
70+
@param category Error category
71+
@param code Error code
72+
*/
73+
OnnxRuntimeException(const CodeLocation& location, const char* failed_condition, const std::string& msg,
74+
common::StatusCategory category,
75+
common::StatusCode code)
76+
: location_{location}, category_(category), code_(code) {
4477
std::ostringstream ss;
4578

4679
ss << location.ToString(CodeLocation::kFilenameAndPath); // output full path in case just the filename is ambiguous
@@ -58,6 +91,14 @@ class OnnxRuntimeException : public std::exception {
5891
what_ = ss.str();
5992
}
6093

94+
common::StatusCategory Category() const noexcept {
95+
return category_;
96+
}
97+
98+
common::StatusCode Code() const noexcept {
99+
return code_;
100+
}
101+
61102
const char* what() const noexcept override {
62103
return what_.c_str();
63104
}
@@ -66,6 +107,8 @@ class OnnxRuntimeException : public std::exception {
66107
const CodeLocation location_;
67108
const std::vector<std::string> stacktrace_;
68109
std::string what_;
110+
common::StatusCategory category_;
111+
common::StatusCode code_;
69112
};
70113

71114
} // namespace onnxruntime

include/onnxruntime/core/common/status.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ enum StatusCode {
4343
MODEL_LOADED = 8,
4444
NOT_IMPLEMENTED = 9,
4545
INVALID_GRAPH = 10,
46-
EP_FAIL = 11
46+
EP_FAIL = 11,
47+
MODEL_LOAD_CANCELED = 12,
4748
};
4849

4950
constexpr const char* StatusCodeToString(StatusCode status) noexcept {
@@ -72,6 +73,8 @@ constexpr const char* StatusCodeToString(StatusCode status) noexcept {
7273
return "INVALID_GRAPH";
7374
case StatusCode::EP_FAIL:
7475
return "EP_FAIL";
76+
case StatusCode::MODEL_LOAD_CANCELED:
77+
return "MODEL_LOAD_CANCELED";
7578
default:
7679
return "GENERAL ERROR";
7780
}
@@ -104,6 +107,8 @@ constexpr HRESULT StatusCodeToHRESULT(StatusCode status) noexcept {
104107
return HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT);
105108
case StatusCode::EP_FAIL:
106109
return HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
110+
case StatusCode::MODEL_LOAD_CANCELED:
111+
return HRESULT_FROM_WIN32(ERROR_CANCELLED);
107112
default:
108113
return E_FAIL;
109114
}

include/onnxruntime/core/session/onnxruntime_c_api.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ typedef enum OrtErrorCode {
255255
ORT_NOT_IMPLEMENTED,
256256
ORT_INVALID_GRAPH,
257257
ORT_EP_FAIL,
258+
ORT_MODEL_LOAD_CANCELED,
258259
} OrtErrorCode;
259260

260261
typedef enum OrtOpAttrType {
@@ -4898,6 +4899,24 @@ struct OrtApi {
48984899
_In_ const int64_t* shape, size_t shape_len,
48994900
ONNXTensorElementDataType type,
49004901
_Outptr_ OrtValue** out);
4902+
4903+
/** \brief sets load cancellation flag to abort session loading process.
4904+
*
4905+
* \param[in] options instance that was passed to the session at creation time.
4906+
* \param[in] cancel setting this to true after model loading process was initiated will
4907+
* attempt to cancel the loading process. If cancellation is successful, CreateSession()
4908+
* CreateSessionFromArray() or any other session creation API that take session options as an
4909+
* argument will return an OrtStatus indicating that session loading was canceled at user request,
4910+
* error code ORT_MODEL_LOAD_CANCELED.
4911+
* The APIs above would not return any valid Session instance. This is the best case effort and the result
4912+
* is not guaranteed. The session may have already been created and initialized
4913+
* before the cancellation request was issued.
4914+
*
4915+
* \snippet{doc} snippets.dox OrtStatus
4916+
*
4917+
*/
4918+
ORT_API2_STATUS(SessionOptionsSetLoadCancellationFlag, _Inout_ OrtSessionOptions* options,
4919+
_In_ bool cancel);
49014920
};
49024921

49034922
/*

include/onnxruntime/core/session/onnxruntime_cxx_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ struct SessionOptionsImpl : ConstSessionOptionsImpl<T> {
928928

929929
SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode); ///< Wraps OrtApi::SetSessionExecutionMode
930930

931+
SessionOptionsImpl& SetLoadCancellationFlag(bool value); ///< Wraps OrtApi::SessionOptionsSetLoadCancellationFlag
932+
931933
SessionOptionsImpl& SetLogId(const char* logid); ///< Wraps OrtApi::SetSessionLogId
932934
SessionOptionsImpl& SetLogSeverityLevel(int level); ///< Wraps OrtApi::SetSessionLogSeverityLevel
933935

include/onnxruntime/core/session/onnxruntime_cxx_inline.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@ inline SessionOptionsImpl<T>& SessionOptionsImpl<T>::SetExecutionMode(ExecutionM
747747
return *this;
748748
}
749749

750+
template <typename T>
751+
inline SessionOptionsImpl<T>& SessionOptionsImpl<T>::SetLoadCancellationFlag(bool value) {
752+
ThrowOnError(GetApi().SessionOptionsSetLoadCancellationFlag(this->p_, value));
753+
return *this;
754+
}
755+
750756
template <typename T>
751757
inline SessionOptionsImpl<T>& SessionOptionsImpl<T>::SetLogId(const char* logid) {
752758
ThrowOnError(GetApi().SetSessionLogId(this->p_, logid));

js/web/test/e2e/exports/testcases/vite-default/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/web/test/e2e/exports/testcases/vite-default/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
},
1414
"devDependencies": {
1515
"@vitejs/plugin-vue": "^5.2.1",
16-
"vite": "^6.2.4"
16+
"vite": "^6.2.5"
1717
}
1818
}

0 commit comments

Comments
 (0)