Skip to content

[NPU][CI] Refactor patch reconciliation - #390

Merged
CalvinXKY merged 5 commits into
vllm-project:ascendfrom
Meihan-chen:codex/npu-patch-series-reconcile
Aug 21, 2026
Merged

[NPU][CI] Refactor patch reconciliation#390
CalvinXKY merged 5 commits into
vllm-project:ascendfrom
Meihan-chen:codex/npu-patch-series-reconcile

Conversation

@Meihan-chen

@Meihan-chen Meihan-chen commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • replace the hard-coded NPU patch inventory with an ordered series.conf
  • persist the image-applied patch series and exact patch bytes under /opt/npu_patch
  • reconcile patch changes through deterministic digest comparison, reverse-order revert, and forward-order apply
  • support patch additions, deletions, renames, reordering, and nested source paths without patch-specific CI branches
  • document when the default image can be reused and when image-build is required
  • add an 8-NPU colocated Qwen3-VL-8B GRPO smoke test to the smk suite
  • fix missing MindSpeed configuration fields when ModelOpt creates transformer configs before MindSpeed patches are registered

Motivation

The previous updater used the current checkout's static PATCH_CONFIGS to represent both the image's OLD patch state and the requested NEW state. This is not reliable when patches are deleted, renamed, reordered, or modified.

PR #385 exposed this issue in NPU CI build 167.
The updater did not retain the deleted megatron_comm.patch and mindspeed.patch, failed to revert the image's Megatron patch, and then tried to apply the new patch on top of the remaining OLD state.

Design

The image stores its ordered OLD series and exact patch bytes under /opt/npu_patch. The current Vime checkout provides the NEW series through docker/npu_patch/series.conf.

Each entry uses:

target_worktree|image_patch|source_patch

If the OLD and NEW digests differ, CI reverts the OLD series from bottom to top and applies the NEW series from top to bottom. This allows the image to revert patches that have already been removed from the current checkout.

Contributor impact

Patch changes remain explicit and reviewable. Contributors must update the patch file, the corresponding docker/Dockerfile.npu apply operation, and docker/npu_patch/series.conf in the same change. Ordinary patch lifecycle changes no longer require patch-specific CI logic.

Signed-off-by: Meihan-chen <zr010426ztt@outlook.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the NPU patch management system in the CI pipeline, introducing a runtime patch reconciler that dynamically applies and reverts patches based on a declared series configuration (series.conf). The update script has been rewritten to calculate patch series digests and reconcile changes, while the Dockerfile now persists the patch state. The review feedback suggests several shell script improvements, including initializing global variables earlier to avoid stale states, removing redundant dry-run git apply --check operations, and wrapping the main function execution to prevent it from running when the script is sourced.

Comment on lines +36 to +41
if [ ! -f "$series_file" ]; then
echo "ERROR: Patch series not found: $series_file" >&2
return 1
fi
}

revert_patch() {
local component_dir="$1"
local patch_name="$2"
local old_patch_path="$3"

if [ -f "$old_patch_path" ]; then
echo "INFO: Attempting to reverse-apply old patch from $old_patch_path"
if git -C "$component_dir" apply --reverse --whitespace=nowarn "$old_patch_path"; then
echo "INFO: Successfully reverted old $patch_name"
else
echo "WARNING: Failed to reverse-apply old patch $patch_name, skipping"
SERIES_ENTRIES=()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Initializing SERIES_ENTRIES after the file existence check can leave the global array in a stale state if the function returns early. It is safer to clear the array at the very beginning of the function to ensure a clean state on failure.

Suggested change
if [ ! -f "$series_file" ]; then
echo "ERROR: Patch series not found: $series_file" >&2
return 1
fi
}
revert_patch() {
local component_dir="$1"
local patch_name="$2"
local old_patch_path="$3"
if [ -f "$old_patch_path" ]; then
echo "INFO: Attempting to reverse-apply old patch from $old_patch_path"
if git -C "$component_dir" apply --reverse --whitespace=nowarn "$old_patch_path"; then
echo "INFO: Successfully reverted old $patch_name"
else
echo "WARNING: Failed to reverse-apply old patch $patch_name, skipping"
SERIES_ENTRIES=()
SERIES_ENTRIES=()
if [ ! -f "$series_file" ]; then
echo "ERROR: Patch series not found: $series_file" >&2
return 1
fi

Comment on lines +111 to +112
git -C "$target" apply --check --whitespace=nowarn "$patch_path"
git -C "$target" apply --whitespace=nowarn "$patch_path"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Running git apply --check followed immediately by git apply on the same patch in the same loop iteration is redundant. git apply is atomic and will fail cleanly if the patch cannot be applied. Removing the dry-run check simplifies the code and avoids running the patch application logic twice.

Suggested change
git -C "$target" apply --check --whitespace=nowarn "$patch_path"
git -C "$target" apply --whitespace=nowarn "$patch_path"
git -C "$target" apply --whitespace=nowarn "$patch_path"

Comment on lines +128 to +129
git -C "$target" apply --reverse --check --whitespace=nowarn "$patch_path"
git -C "$target" apply --reverse --whitespace=nowarn "$patch_path"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly to the apply step, running git apply --reverse --check followed immediately by git apply --reverse is redundant. Removing the dry-run check simplifies the code.

Suggested change
git -C "$target" apply --reverse --check --whitespace=nowarn "$patch_path"
git -C "$target" apply --reverse --whitespace=nowarn "$patch_path"
git -C "$target" apply --reverse --whitespace=nowarn "$patch_path"

Comment on lines +203 to +224
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
case "${1:-}" in
series-digest)
if [ "$#" -ne 3 ]; then
echo "Usage: $0 series-digest SERIES_FILE SOURCE_ROOT" >&2
exit 2
fi
series_digest "$2" "$3"
exit
;;
reconcile)
if [ "$#" -ne 5 ]; then
echo "Usage: $0 reconcile OLD_SERIES OLD_ROOT NEW_SERIES NEW_ROOT" >&2
exit 2
fi
reconcile_series "$2" "$3" "$4" "$5"
exit
;;
esac
fi

main

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Executing main at the global scope means it will run automatically when the script is sourced (e.g., for testing or reusing helper functions). Wrapping main inside the if [[ "${BASH_SOURCE[0]}" == "$0" ]] block as the default case ensures it only runs when the script is executed directly.

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
    case "${1:-}" in
        series-digest)
            if [ "$#" -ne 3 ]; then
                echo "Usage: $0 series-digest SERIES_FILE SOURCE_ROOT" >&2
                exit 2
            fi
            series_digest "$2" "$3"
            exit
            ;;
        reconcile)
            if [ "$#" -ne 5 ]; then
                echo "Usage: $0 reconcile OLD_SERIES OLD_ROOT NEW_SERIES NEW_ROOT" >&2
                exit 2
            fi
            reconcile_series "$2" "$3" "$4" "$5"
            exit
            ;;
        *)
            main
            ;;
    esac
fi

Signed-off-by: Meihan-chen <zr010426ztt@outlook.com>
@Meihan-chen
Meihan-chen force-pushed the codex/npu-patch-series-reconcile branch from e619341 to 44773c0 Compare August 19, 2026 06:09
@Meihan-chen
Meihan-chen marked this pull request as ready for review August 19, 2026 06:10
@Meihan-chen
Meihan-chen force-pushed the codex/npu-patch-series-reconcile branch 4 times, most recently from 5e548d6 to 97134d2 Compare August 19, 2026 09:26
Signed-off-by: Meihan-chen <zr010426ztt@outlook.com>
@Meihan-chen
Meihan-chen force-pushed the codex/npu-patch-series-reconcile branch from 97134d2 to 58aa103 Compare August 19, 2026 09:46
Signed-off-by: Meihan-chen <zr010426ztt@outlook.com>
@Meihan-chen
Meihan-chen force-pushed the codex/npu-patch-series-reconcile branch from 0b0170f to 80832d8 Compare August 20, 2026 07:27
@Meihan-chen Meihan-chen mentioned this pull request Aug 20, 2026
4 tasks
Signed-off-by: Meihan-chen <zr010426ztt@outlook.com>

@CalvinXKY CalvinXKY left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CalvinXKY
CalvinXKY merged commit 9afaf89 into vllm-project:ascend Aug 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants