-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow setting runtime handles (alternative) (#1002)
This PR is an alternative way of #997 to implement allowing users to set runtime handles. The basic idea is to create a JSON string representing the `Config` class from the `RuntimeSettings`, and the `Config` class will merge them. Currently this PR is not working because of the following: - The existing JSON parser does not support multiple entries in `provider_options` The following JSON will fail to parse. ```json { "model": { "decoder": { "session_options": { "provider_options": [ { "webgpu": { } }, { "dml": {} } ] }, }, }, } ``` - When trying to specify JSON overlay, two "webgpu" items does not merge. genai_config.json: ```json { "model": { "decoder": { "session_options": { "provider_options": [ { "webgpu": { "abc": "123" } } ] }, }, }, } ``` generated overlay config: ``` { "model": { "decoder": { "session_options": { "provider_options": [ { "webgpu": { "dawnProcTable": "12345678" } } ] } } } } ``` Result: ![image](https://github.com/user-attachments/assets/adf649bd-8d7b-4b2e-a8f8-6141d04eb7ee) This PR depends on a code change to the Config class to support the expected parsing behaviors. --------- Co-authored-by: Ryan Hill <[email protected]>
- Loading branch information
1 parent
147a311
commit d58daf0
Showing
9 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,43 @@ | ||
#include "runtime_settings.h" | ||
|
||
namespace Generators { | ||
|
||
std::unique_ptr<RuntimeSettings> CreateRuntimeSettings() { | ||
return std::make_unique<RuntimeSettings>(); | ||
} | ||
|
||
std::string RuntimeSettings::GenerateConfigOverlay() const { | ||
// #if USE_WEBGPU | ||
constexpr std::string_view webgpu_overlay_pre = R"({ | ||
"model": { | ||
"decoder": { | ||
"session_options": { | ||
"provider_options": [ | ||
{ | ||
"webgpu": { | ||
"dawnProcTable": ")"; | ||
constexpr std::string_view webgpu_overlay_post = R"(" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
)"; | ||
|
||
auto it = handles_.find("dawnProcTable"); | ||
if (it != handles_.end()) { | ||
void* dawn_proc_table_handle = it->second; | ||
std::string overlay; | ||
overlay.reserve(webgpu_overlay_pre.size() + webgpu_overlay_post.size() + 20); // Optional small optimization of buffer size | ||
overlay += webgpu_overlay_pre; | ||
overlay += std::to_string((size_t)(dawn_proc_table_handle)); | ||
overlay += webgpu_overlay_post; | ||
return overlay; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
} // namespace Generators |
This file contains 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,20 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <memory> | ||
#include <unordered_map> | ||
|
||
namespace Generators { | ||
|
||
// This struct should only be used for runtime settings that are not able to be put into config. | ||
struct RuntimeSettings { | ||
RuntimeSettings() = default; | ||
|
||
std::string GenerateConfigOverlay() const; | ||
|
||
std::unordered_map<std::string, void*> handles_; | ||
}; | ||
|
||
std::unique_ptr<RuntimeSettings> CreateRuntimeSettings(); | ||
|
||
} // namespace Generators |