mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2026-08-21 22:43:44 +00:00
Some checks failed
Book-CI / test (push) Waiting to run
Book-CI / test-1 (push) Waiting to run
Book-CI / test-2 (push) Waiting to run
Deploy / deploy (macos-latest) (push) Waiting to run
Deploy / deploy (ubuntu-latest) (push) Waiting to run
Deploy / deploy (windows-latest) (push) Waiting to run
Release Fake Tag / publish (push) Has been cancelled
Release to PyPI / Build & publish sglang-kt (push) Has been cancelled
Release to PyPI / Build kt-kernel (Python 3.11) (push) Has been cancelled
Release to PyPI / Build kt-kernel (Python 3.12) (push) Has been cancelled
Release to PyPI / Publish kt-kernel to PyPI (push) Has been cancelled
Release to PyPI / Build & publish ktransformers shell sdist (push) Has been cancelled
* feat(sft): support distributed activation reuse policies * feat(sft): add frozen-base INT8 LoRA training * fix(sft): make INT8 expert LoRA rank-zero authoritative * fix(sft): preserve DeepSeek router LoRA routing * feat(sft): enable persistent INT8 LoRA training * perf(sft): accelerate INT8 VNNI with oneDNN BRGEMM * perf(int8): fuse oneDNN compensation into backward repack * [feat]: support BF16 expert LoRA training * [fix]: honor forwarded activation policy in SFT workers * feat(sft): add native block-FP8 routed expert LoRA * feat(sft): expose explicit expert placeholder ownership * fix(sft): publish fused adapter artifacts atomically * feat(sft): own artifact and adapter lifecycle contracts * fix(sft): harden artifact and rank-local contracts * fix(sft): auto-adapt owner before adapter restore * style(sft): keep lifecycle comments concise * fix(sft): require fused adapter manifests * test(sft): use spawn for distributed workers * fix(sft): preserve runtime checkpoint metadata * fix(sft): validate wrapped runtime configuration * fix(sft): preserve expert format provenance * fix(sft): own routed experts during device dispatch * test(sft): lock explicit quantization conflict * fix(cpu): make shared memory buffers lifetime-safe * release: prepare v0.7.0
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import importlib.util
|
|
import os
|
|
import sys
|
|
import types
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
|
|
PACKAGE_PATH = Path(__file__).resolve().parents[2] / "python" / "sft"
|
|
PACKAGE_NAME = "kt_sft_config_under_test"
|
|
package = types.ModuleType(PACKAGE_NAME)
|
|
package.__path__ = [str(PACKAGE_PATH)]
|
|
sys.modules[PACKAGE_NAME] = package
|
|
SPEC = importlib.util.spec_from_file_location(f"{PACKAGE_NAME}.config", PACKAGE_PATH / "config.py")
|
|
assert SPEC is not None and SPEC.loader is not None
|
|
config = importlib.util.module_from_spec(SPEC)
|
|
sys.modules[SPEC.name] = config
|
|
SPEC.loader.exec_module(config)
|
|
|
|
|
|
def test_detect_physical_cpu_count_deduplicates_smt_siblings():
|
|
topology = {
|
|
0: (0, 0),
|
|
1: (0, 1),
|
|
2: (0, 0),
|
|
3: (0, 1),
|
|
4: (1, 0),
|
|
5: (1, 0),
|
|
}
|
|
with (
|
|
patch.object(config, "_available_cpu_ids", return_value=set(topology)),
|
|
patch.object(config, "_read_cpu_topology", side_effect=topology.get),
|
|
):
|
|
assert config.detect_physical_cpu_count() == 3
|
|
|
|
|
|
def test_configure_omp_threads_replaces_accelerate_single_thread_default():
|
|
with (
|
|
patch.dict(os.environ, {"OMP_NUM_THREADS": "1"}, clear=False),
|
|
patch.object(config, "detect_physical_cpu_count", return_value=96),
|
|
patch.object(config, "_set_torch_num_threads") as set_torch_threads,
|
|
):
|
|
os.environ.pop("ACCELERATE_KT_OMP_NUM_THREADS", None)
|
|
assert config.configure_omp_threads() == 96
|
|
assert os.environ["OMP_NUM_THREADS"] == "96"
|
|
set_torch_threads.assert_called_once_with(96)
|
|
|
|
|
|
def test_configure_omp_threads_preserves_explicit_generic_value():
|
|
with (
|
|
patch.dict(os.environ, {"OMP_NUM_THREADS": "48"}, clear=False),
|
|
patch.object(config, "_set_torch_num_threads") as set_torch_threads,
|
|
):
|
|
os.environ.pop("ACCELERATE_KT_OMP_NUM_THREADS", None)
|
|
assert config.configure_omp_threads() == 48
|
|
set_torch_threads.assert_called_once_with(48)
|
|
|
|
|
|
def test_configure_omp_threads_supports_explicit_single_thread_override():
|
|
with (
|
|
patch.dict(
|
|
os.environ,
|
|
{"OMP_NUM_THREADS": "96", "ACCELERATE_KT_OMP_NUM_THREADS": "1"},
|
|
clear=False,
|
|
),
|
|
patch.object(config, "_set_torch_num_threads") as set_torch_threads,
|
|
):
|
|
assert config.configure_omp_threads() == 1
|
|
assert os.environ["OMP_NUM_THREADS"] == "1"
|
|
set_torch_threads.assert_called_once_with(1)
|