-
Notifications
You must be signed in to change notification settings - Fork 13
add qwen3 test ci #49
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
Merged
+226
−35
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Copyright (c) PyPTO Contributors. | ||
| # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| # CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| # Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| # See LICENSE in the root of the software repository for the full text of the License. | ||
| # ----------------------------------------------------------------------------------------------------------- | ||
|
|
||
| """Qwen3 output accuracy guard for CI.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
| if str(ROOT) not in sys.path: | ||
| sys.path.insert(0, str(ROOT)) | ||
|
|
||
|
|
||
| MODEL_DIR_ENV = os.environ.get("PYPTO_QWEN3_MODEL_DIR") | ||
| if MODEL_DIR_ENV is None: | ||
| pytest.fail("PYPTO_QWEN3_MODEL_DIR is required") | ||
| MODEL_DIR = Path(MODEL_DIR_ENV) | ||
| MODEL_ID = "qwen3-14b-accuracy" | ||
| PLATFORM = os.environ.get("PYPTO_QWEN3_PLATFORM", "a2a3") | ||
| DEVICE_ID_ENV = os.environ.get("DEVICE_ID") | ||
| if DEVICE_ID_ENV is None: | ||
| pytest.fail("DEVICE_ID is required") | ||
| DEVICE_ID = int(DEVICE_ID_ENV) | ||
| PROMPT = "The capital of France is" | ||
| MAX_NEW_TOKENS = 8 | ||
|
|
||
| EXPECTED_TOKEN_IDS = [12095, 13, 576, 6722, 315, 9625, 374, 12095] | ||
|
|
||
|
|
||
| def test_qwen3_output_matches_expected_tokens(): | ||
| if not MODEL_DIR or not MODEL_DIR.is_dir(): | ||
| pytest.fail(f"Qwen3 model weights not found: {MODEL_DIR}") | ||
|
|
||
| from examples.model.qwen3_14b.runner.npu_executor import Qwen314BPyptoExecutor | ||
| from python.core.engine import LLMEngine | ||
| from python.core.kv_cache import KvCacheManager | ||
| from python.core.types import GenerateConfig, RuntimeConfig | ||
|
|
||
| kv_cache_manager = KvCacheManager() | ||
| executor = Qwen314BPyptoExecutor( | ||
| kv_cache_manager, | ||
| platform=PLATFORM, | ||
| device_id=DEVICE_ID, | ||
| ) | ||
| engine = LLMEngine(kv_cache_manager=kv_cache_manager, executor=executor) | ||
|
|
||
| try: | ||
| engine.init_model( | ||
| model_id=MODEL_ID, | ||
| model_dir=str(MODEL_DIR), | ||
| model_format="huggingface", | ||
| runtime_config=RuntimeConfig( | ||
| page_size=128, | ||
| max_batch_size=16, | ||
| max_seq_len=512, | ||
| max_new_tokens=MAX_NEW_TOKENS, | ||
| device="cpu", | ||
| kv_dtype="bfloat16", | ||
| weight_dtype="float32", | ||
| ), | ||
| ) | ||
| result = engine.generate_result( | ||
| MODEL_ID, | ||
| PROMPT, | ||
| GenerateConfig( | ||
| max_new_tokens=MAX_NEW_TOKENS, | ||
| temperature=0.0, | ||
| top_p=1.0, | ||
| top_k=None, | ||
| ), | ||
| ) | ||
| finally: | ||
| executor.close() | ||
| assert result.token_ids == EXPECTED_TOKEN_IDS, ( | ||
| f"Qwen3 output changed for prompt {PROMPT!r}:\n" | ||
| f"expected token_ids: {EXPECTED_TOKEN_IDS}\n" | ||
| f"actual token_ids: {result.token_ids}\n" | ||
| f"actual text: {result.text!r}\n" | ||
| f"finish_reason: {result.finish_reason}" | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
LLMEngineinitialization fails, theexecutor(which may have already allocated NPU resources) will not be closed because thetry...finallyblock starts after its initialization. Move thetryblock up to immediately follow the creation ofexecutorto ensure resources are always cleaned up.