[Autotuner] Log autotuner config in readable json format. When debugging the autotuner we often want to know the values of the AutotuneConfig.

PiperOrigin-RevId: 847683182
This commit is contained in:
Dirk Hornung
2025-12-22 02:41:59 -08:00
committed by TensorFlower Gardener
parent 23dd865ee5
commit f5b102299e
4 changed files with 61 additions and 0 deletions

View File

@@ -499,6 +499,7 @@ absl::StatusOr<std::vector<Autotuner::ConfigResult>> Autotuner::ProfileAll(
std::optional<ScopedShapedBuffer> reference_output;
if (autotune_config_.check_buffers) {
VLOG(2) << "Checking buffers";
reference_output = GetReferenceOutput(candidates, *input_buffers);
if (!reference_output.has_value()) {
LOG(WARNING) << "No reference output found even though buffer checking "
@@ -605,6 +606,8 @@ std::optional<ScopedShapedBuffer> Autotuner::GetReferenceOutput(
continue;
}
if (profile_result.value().output_buffer.has_value()) {
VLOG(2) << "Found reference output for config: "
<< candidate.config.ToString();
return std::move(profile_result.value().output_buffer.value());
}
}
@@ -732,4 +735,28 @@ std::string Autotuner::Config::ToString() const {
UnpackedAnyShortDebugString(*backend_config));
}
std::string AutotuneConfig::ToString() const {
return absl::StrFormat(
"{\n"
" \"check_buffers\": %s,\n"
" \"relative_tolerance\": %f,\n"
" \"crash_on_check_failure\": %s,\n"
" \"optimize_scratch_bytes\": %s,\n"
" \"scratch_bytes_window_size_us\": %d,\n"
" \"expect_all_instructions_in_cache\": %s,\n"
" \"dump_logs_to\": \"%s\",\n"
" \"exclude_cublas_config\": %s,\n"
" \"select_first_config\": %s,\n"
" \"use_default_config\": %s,\n"
" \"dump_hlos\": %s\n"
"}",
check_buffers ? "true" : "false", relative_tolerance,
crash_on_check_failure ? "true" : "false",
optimize_scratch_bytes ? "true" : "false", scratch_bytes_window_size_us,
expect_all_instructions_in_cache ? "true" : "false", dump_logs_to,
exclude_cublas_config ? "true" : "false",
select_first_config ? "true" : "false",
use_default_config ? "true" : "false", dump_hlos ? "true" : "false");
}
} // namespace xla

View File

@@ -87,6 +87,8 @@ struct AutotuneConfig {
// If true, dump the autotuned instructions to the modules's xla_dump_to or
// to stdout if not set.
bool dump_hlos = false;
std::string ToString() const;
};
class Autotuner {

View File

@@ -986,5 +986,36 @@ TEST_F(AutotunerTest, DumpHlos) {
MatchesRegex(".*\\.test_module\\.autotuner_1\\.add\\.before\\.txt")));
}
TEST(AutotuneConfigTest, ToString) {
AutotuneConfig config;
config.check_buffers = true;
config.relative_tolerance = 1e-4;
config.crash_on_check_failure = false;
config.optimize_scratch_bytes = true;
config.scratch_bytes_window_size_us = 10;
config.expect_all_instructions_in_cache = false;
config.dump_logs_to = "/tmp/log";
config.exclude_cublas_config = true;
config.select_first_config = false;
config.use_default_config = true;
config.dump_hlos = false;
std::string expected =
"{\n"
" \"check_buffers\": true,\n"
" \"relative_tolerance\": 0.000100,\n"
" \"crash_on_check_failure\": false,\n"
" \"optimize_scratch_bytes\": true,\n"
" \"scratch_bytes_window_size_us\": 10,\n"
" \"expect_all_instructions_in_cache\": false,\n"
" \"dump_logs_to\": \"/tmp/log\",\n"
" \"exclude_cublas_config\": true,\n"
" \"select_first_config\": false,\n"
" \"use_default_config\": true,\n"
" \"dump_hlos\": false\n"
"}";
EXPECT_EQ(config.ToString(), expected);
}
} // namespace
} // namespace xla

View File

@@ -103,6 +103,7 @@ absl::StatusOr<std::unique_ptr<AutotunerPass>> AutotunerPass::Create(
bool is_deviceless = stream_executor == nullptr;
AutotuneConfig autotune_config =
GetAutotuneConfig(debug_options, is_deviceless, optimize_scratch_bytes);
VLOG(1) << "Autotune config: " << autotune_config.ToString();
if (!is_deviceless) {
profiler = GpuProfiler::Create(