Skip to content

Commit 46d066e

Browse files
committed
fix: guard retain_pinned_cpu_buffers by inspecting TE signature
Custom TE builds (e.g. v0.1.0+te2.9.0) may report >= 2.5.0 via the +te version tag but lack the retain_pinned_cpu_buffers parameter in get_cpu_offload_context. Use inspect.signature to check the actual function before passing the kwarg.
1 parent 0c3da71 commit 46d066e

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

megatron/core/extensions/transformer_engine.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,16 +2561,33 @@ def get_cpu_offload_context(
25612561
):
25622562
"""Get CPU offload context and sync function."""
25632563
if is_te_min_version("2.5.0"):
2564-
# Enables the additional double buffering switch for activations during LLM training
2565-
context, sync_func = _get_cpu_offload_context(
2566-
enabled,
2567-
num_layers,
2568-
model_layers,
2569-
activation_offloading,
2570-
weight_offloading,
2571-
double_buffering,
2572-
retain_pinned_cpu_buffers=retain_pinned_cpu_buffers,
2573-
)
2564+
# FlagScale Begin
2565+
# Check whether the installed TE actually supports retain_pinned_cpu_buffers,
2566+
# since custom TE builds (e.g. v0.1.0+te2.9.0) may report >= 2.5.0 but
2567+
# lack this parameter.
2568+
import inspect
2569+
2570+
_sig = inspect.signature(_get_cpu_offload_context)
2571+
if "retain_pinned_cpu_buffers" in _sig.parameters:
2572+
context, sync_func = _get_cpu_offload_context(
2573+
enabled,
2574+
num_layers,
2575+
model_layers,
2576+
activation_offloading,
2577+
weight_offloading,
2578+
double_buffering,
2579+
retain_pinned_cpu_buffers=retain_pinned_cpu_buffers,
2580+
)
2581+
else:
2582+
context, sync_func = _get_cpu_offload_context(
2583+
enabled,
2584+
num_layers,
2585+
model_layers,
2586+
activation_offloading,
2587+
weight_offloading,
2588+
double_buffering,
2589+
)
2590+
# FlagScale End
25742591
elif is_te_min_version("1.10.0.dev0"):
25752592
context, sync_func = _get_cpu_offload_context(
25762593
enabled, num_layers, model_layers, activation_offloading, weight_offloading

0 commit comments

Comments
 (0)