Skip to content

Commit 60aeeca

Browse files
ezhulenevGoogle-ML-Automation
authored andcommitted
[xla:cpu] Strip payload from literal protos when passing it to CpuExecutable
PiperOrigin-RevId: 707170581
1 parent 20a4825 commit 60aeeca

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

xla/service/cpu/cpu_compiler.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,23 @@ inline void VlogMaxIsa(absl::string_view max_cpu_isa) {
13301330
}
13311331
}
13321332

1333+
// We keep HloProto in the CpuExecutable, but we don't need to keep literals
1334+
// payload in it as we use it only for debugging and memory analysis.
1335+
static void StripPayloadFromLiteralProto(HloProto& proto) {
1336+
auto* module = proto.mutable_hlo_module();
1337+
for (auto& computation : *module->mutable_computations()) {
1338+
for (auto& instruction : *computation.mutable_instructions()) {
1339+
// We only keep literal shape to correctly estimate memory usage of the
1340+
// HLO module, but we don't need the actual literal data.
1341+
if (instruction.has_literal()) {
1342+
LiteralProto literal;
1343+
*literal.mutable_shape() = instruction.literal().shape();
1344+
*instruction.mutable_literal() = std::move(literal);
1345+
}
1346+
}
1347+
}
1348+
}
1349+
13331350
absl::StatusOr<std::unique_ptr<CpuExecutable>>
13341351
CpuCompiler::CompileLegacyCpuExecutable(std::unique_ptr<HloModule> module) {
13351352
TraceMe trace([&] {
@@ -1452,6 +1469,7 @@ CpuCompiler::CompileLegacyCpuExecutable(std::unique_ptr<HloModule> module) {
14521469
*hlo_proto->mutable_hlo_module() = cpu_executable->module().ToProto();
14531470
*hlo_proto->mutable_buffer_assignment() =
14541471
cpu_executable->buffer_assignment().ToProto();
1472+
StripPayloadFromLiteralProto(*hlo_proto);
14551473
cpu_executable->set_hlo_proto(std::move(hlo_proto));
14561474
return cpu_executable;
14571475
};

0 commit comments

Comments
 (0)