Skip to content

kali20gakki/msAgent / skills/quantizer/quantization-expert-experience-tuning-rules

quantization-expert-experience-tuning-rules

Verified

量化专家经验调优库:按「L1 通用专家调优意见 → L2 结构化专家调优意见 → L3 模型专属专家调优意见」三级递进, 输出量化精度调优的完整手段(离群值抑制 / 量化方法·粒度·对称性选型 / 校准集调整 / 敏感层回退 / 模型专属策略), 每条结论附专家原因分析与专家意见可信度等级。 本 Skill 是专家经验库,负责说明可选离群值抑制算法并询问用户选择哪些算法,以及回答「怎么调、哪些层需要回退及为什么」;不运行离群值抑制 processor,不修改 YAML、不执行量化、不做 EP 检查 / 服务化 / 任务评测。

scripts/yaml_utils.py

View on GitHub
# -------------------------------------------------------------------------
# This file is part of the MindStudio project.
# Copyright (c) 2026 Huawei Technologies Co.,Ltd.
#
# MindStudio is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
#          http://license.coscl.org.cn/MulanPSL2
#
# 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 FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# -------------------------------------------------------------------------

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Thin YAML helpers used by the practice-dit skill.

Practice YAMLs are *small* (one ``spec`` block, one ``process`` list, one
``exclude`` list) — we deliberately avoid pulling in msmodelslim's full
yaml_validation_helpers stack so the skill has no transitive dependency on
the quant framework being installed. ``PyYAML`` is the only requirement.
"""

from __future__ import annotations

import sys
from pathlib import Path
from typing import Any, Dict


def _yaml():
    try:
        import yaml  # type: ignore

        return yaml
    except ImportError as exc:  # pragma: no cover — env-mismatch guard
        raise RuntimeError(
            "PyYAML is required by the quantization experience library. "
            "Install it via `pip install pyyaml`."
        ) from exc


def load_yaml(path: str | Path) -> Dict[str, Any]:
    """Load a YAML file into a Python dict. Always returns ``{}`` for empty files."""
    p = Path(path).expanduser().resolve()
    if not p.is_file():
        raise FileNotFoundError(f"YAML not found: {p}")
    text = p.read_text(encoding="utf-8")
    if not text.strip():
        return {}
    parsed = _yaml().safe_load(text)
    return parsed or {}


def dump_yaml(obj: Dict[str, Any], path: str | Path, *, sort_keys: bool = False) -> None:
    """Dump a Python dict to YAML with a stable style (block, indent=2)."""
    p = Path(path).expanduser().resolve()
    p.parent.mkdir(parents=True, exist_ok=True)
    text = _yaml().safe_dump(
        obj,
        sort_keys=sort_keys,
        allow_unicode=True,
        default_flow_style=False,
        indent=2,
        width=120,
    )
    p.write_text(text, encoding="utf-8")


def find_exclude_target(process: list) -> int | None:
    """Return index of the first ``process`` step whose ``exclude`` is a list, or ``None``.

    Shared by ``merge_exclude`` (read-only) and ``apply_rollback`` (needs the same
    index to write back the merged list without re-scanning).
    """
    for idx, step in enumerate(process):
        if isinstance(step, dict) and isinstance(step.get("exclude"), list):
            return idx
    return None


def merge_exclude(
    base_practice: Dict[str, Any],
    extras: list[str],
) -> tuple[list[str], list[str]]:
    """Append ``extras`` to the first ``spec.process[*].exclude`` list.

    Returns ``(merged, original)`` so callers that need to compute the
    ``appended`` delta (e.g. ``apply_rollback``) don't have to re-locate the
    target step. Honors the existing ``exclude`` list — duplicates are dropped,
    and the *original order* of the base list is preserved so YAML diffs stay
    readable. Does **not** mutate the input dict.
    """
    spec = base_practice.get("spec")
    if not isinstance(spec, dict):
        raise ValueError("base_practice has no `spec` mapping")
    process = spec.get("process")
    if not isinstance(process, list) or not process:
        raise ValueError("base_practice.spec.process must be a non-empty list")

    target_idx = find_exclude_target(process)
    if target_idx is None:
        raise ValueError(
            "No process step with `exclude` list found in base_practice; "
            "expert_rollback requires an existing exclude list to append to."
        )

    base_exclude = list(process[target_idx]["exclude"])
    seen = set(base_exclude)
    merged: list[str] = list(base_exclude)
    for entry in extras:
        if entry and entry not in seen:
            merged.append(entry)
            seen.add(entry)

    return merged, base_exclude
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall