Skip to content
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

Add support for parsing enum values in ExecuteOptions::ApplyAllOptionOverrides. #17274

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions xla/pjrt/pjrt_executable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,27 @@ absl::Status CompileOptions::ApplyOption(const std::string& key,
std::holds_alternative<double>(value)) {
reflection->SetDouble(&debug_options, xla_field, std::get<double>(value));
return absl::OkStatus();
} else if (xla_field->type() == tsl::protobuf::FieldDescriptor::TYPE_ENUM) {
if (std::holds_alternative<int64_t>(value)) {
if (xla_field->is_repeated()) {
reflection->AddEnumValue(&debug_options, xla_field,
std::get<int64_t>(value));
} else {
reflection->SetEnumValue(&debug_options, xla_field,
std::get<int64_t>(value));
}
} else {
auto enum_desc = xla_field->enum_type()->FindValueByName(
std::get<std::string>(value));
if (enum_desc != nullptr) {
if (xla_field->is_repeated()) {
reflection->AddEnum(&debug_options, xla_field, enum_desc);
} else {
reflection->SetEnum(&debug_options, xla_field, enum_desc);
}
}
}
return absl::OkStatus();
} else {
return InvalidArgument(
"While setting option %s, '%s' is not a valid %s value.", key,
Expand Down Expand Up @@ -636,6 +657,25 @@ absl::Status CompileOptions::ApplyOptionFromString(
reflection->SetBool(&debug_options, field, bvalue);
return absl::OkStatus();
}
} else if (field->type() == tsl::protobuf::FieldDescriptor::TYPE_ENUM) {
int int_value;
if (absl::SimpleAtoi(value, &int_value)) {
if (field->is_repeated()) {
reflection->AddEnumValue(&debug_options, field, int_value);
} else {
reflection->SetEnumValue(&debug_options, field, int_value);
}
return absl::OkStatus();
} else {
auto enum_desc = field->enum_type()->FindValueByName(value);
if (enum_desc != nullptr) {
if (field->is_repeated()) {
reflection->AddEnum(&debug_options, field, enum_desc);
} else {
reflection->SetEnum(&debug_options, field, enum_desc);
}
}
}
}
return InvalidArgument(
"While setting option %s, '%s' is not a valid %s value.", field->name(),
Expand Down
5 changes: 4 additions & 1 deletion xla/pjrt/pjrt_executable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ TEST(ExecuteOptionsTest, SendRecvNotSupported) {
"ExecuteOptions with send/recv calbacks is not serializable"));
}

TEST(ExecuteOptionsTest, ApplyOptionsCanParseStrings) {
TEST(ExecuteOptionsTest, ApplyOptionsCanParseStringsAndEnums) {
using OptionOverride = std::variant<std::string, bool, int64_t, double>;
std::vector<std::pair<std::string, OptionOverride>> env_override_options;
env_override_options = {
{"xla_gpu_use_runtime_fusion", std::string("True")},
{"xla_gpu_graph_min_graph_size", std::string("2")},
{"xla_gpu_disable_async_collectives", std::string("2")},
{"xla_gpu_redzone_scratch_max_megabytes", std::string("3400")},
{"xla_gpu_auto_spmd_partitioning_memory_budget_ratio", 0.9},
{"xla_gpu_pgle_profile_file_or_directory_path", std::string("abc")}};
Expand All @@ -112,6 +113,8 @@ TEST(ExecuteOptionsTest, ApplyOptionsCanParseStrings) {
EXPECT_FLOAT_EQ(
debug_options.xla_gpu_auto_spmd_partitioning_memory_budget_ratio(), 0.9);
EXPECT_EQ(debug_options.xla_gpu_pgle_profile_file_or_directory_path(), "abc");
EXPECT_EQ(debug_options.xla_gpu_disable_async_collectives().size(), 1);
EXPECT_EQ(debug_options.xla_gpu_disable_async_collectives()[0], 2);
}

TEST(CompiledMemoryStatsTest, Serialization) {
Expand Down
Loading