-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IFRT] Add
custom_options
in ifrt::ExecuteOptions
The users can provide any runtime-specific execution options at `ifrt::LoadedExecutable::Execute()` using `ifrt::ExecuteOptions::custom_options`. These options are intended to convey small per-execution metadata that are to be used by implementation internals with little to (ideally) no interaction with IFRT API semantics. Example use cases are propagating a profiling key, which currently goes out of scope of IFRT APIs. PiperOrigin-RevId: 702546163
- Loading branch information
1 parent
6267dba
commit 5ad6651
Showing
5 changed files
with
89 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Copyright 2024 The OpenXLA Authors. | ||
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 "xla/python/ifrt/executable.h" | ||
|
||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
#include "xla/python/ifrt/attribute_map.h" | ||
#include "tsl/platform/statusor.h" | ||
#include "tsl/platform/test.h" | ||
|
||
namespace xla { | ||
namespace ifrt { | ||
|
||
using ::testing::Pair; | ||
using ::testing::UnorderedElementsAre; | ||
|
||
TEST(ExecuteOptionsTest, RoundTrip) { | ||
LoadedExecutable::ExecuteOptions options; | ||
options.launch_id = 1234; | ||
options.non_donatable_input_indices.insert(0); | ||
options.non_donatable_input_indices.insert(3); | ||
options.fill_status = true; | ||
options.custom_options = AttributeMap( | ||
AttributeMap::Map({{"foo", AttributeMap::StringValue("bar")}})); | ||
TF_ASSERT_OK_AND_ASSIGN(ExecuteOptionsProto serialized, options.ToProto()); | ||
TF_ASSERT_OK_AND_ASSIGN( | ||
auto deserialized, | ||
LoadedExecutable::ExecuteOptions::FromProto(serialized)); | ||
EXPECT_EQ(deserialized.launch_id, 1234); | ||
EXPECT_THAT(deserialized.non_donatable_input_indices, | ||
UnorderedElementsAre(0, 3)); | ||
EXPECT_TRUE(deserialized.fill_status); | ||
ASSERT_TRUE(deserialized.custom_options.has_value()); | ||
EXPECT_THAT( | ||
deserialized.custom_options->map(), | ||
UnorderedElementsAre(Pair("foo", AttributeMap::StringValue("bar")))); | ||
} | ||
|
||
} // namespace ifrt | ||
} // namespace xla |
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