-
Notifications
You must be signed in to change notification settings - Fork 2k
[None][feat] Add Request specific exception #6931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f687020
Remove PP check
3f6397f
Add c++ requestSpecificExeception
bccdecd
Add unittest
b443f70
Propagate request id in error
a9f5109
Throw Exception in Transfer Session
7a74988
Catch exception in python
5a703f6
Fix error
b487a5a
Add nanobind
a325064
Refactor
2774651
Fix nanobind error
7a5c004
Fix error
4e9c964
Fix error
4fbbed4
Refactor interface
0e37973
Fix error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add nanobind
Signed-off-by: Shunkang <182541032+Shunkangz@users.noreply.github.co>
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "tllmExceptions.h" | ||
| #include "tensorrt_llm/common/tllmException.h" | ||
| #include <nanobind/nanobind.h> | ||
|
|
||
| namespace tc = tensorrt_llm::common; | ||
| namespace nb = nanobind; | ||
|
|
||
| namespace tensorrt_llm::nanobind::common | ||
| { | ||
|
|
||
| void initExceptionsBindings(nb::module_& m) | ||
| { | ||
| // Bind the RequestErrorCode enum | ||
| nb::enum_<tc::RequestErrorCode>(m, "RequestErrorCode") | ||
| .value("UNKNOWN_ERROR", tc::RequestErrorCode::kUNKNOWN_ERROR) | ||
| .value("NETWORK_ERROR", tc::RequestErrorCode::kNETWORK_ERROR) | ||
| .export_values(); | ||
|
|
||
| // Create the RequestSpecificException Python exception class | ||
| static nb::object request_specific_exc = nb::exception<tc::RequestSpecificException>(m, "RequestSpecificException"); | ||
|
|
||
| // Add attributes to the Python exception class | ||
| request_specific_exc.attr("request_id") = nb::none; | ||
| request_specific_exc.attr("error_code") = nb::none; | ||
|
|
||
| // Register exception translator to convert C++ exceptions to Python | ||
| nb::register_exception_translator( | ||
| [](std::exception_ptr const& p, void*) | ||
| { | ||
| try | ||
| { | ||
| if (p) | ||
| std::rethrow_exception(p); | ||
| } | ||
| catch (const tc::RequestSpecificException& e) | ||
| { | ||
| // Create a Python exception with the request ID and error code information | ||
| nb::object py_exc = nb::cast(e); | ||
| nb::object request_id = nb::cast(e.getRequestId()); | ||
| nb::object error_code = nb::cast(static_cast<uint32_t>(e.getErrorCode())); | ||
Shunkangz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Set additional attributes on the exception | ||
| py_exc.attr("request_id") = request_id; | ||
| py_exc.attr("error_code") = error_code; | ||
|
|
||
| PyErr_SetObject(request_specific_exc.ptr(), py_exc.ptr()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| } // namespace tensorrt_llm::nanobind::common | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include <nanobind/nanobind.h> | ||
|
|
||
| namespace nb = nanobind; | ||
|
|
||
| namespace tensorrt_llm::nanobind::common | ||
| { | ||
|
|
||
| void initExceptionsBindings(nb::module_& m); | ||
|
|
||
| } // namespace tensorrt_llm::nanobind::common |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.