[verified] feat: complete Ralph task workstreams
This commit is contained in:
@@ -237,6 +237,85 @@ def _cmd_config(args) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _doctor_overrides(args) -> dict:
|
||||
"""CLI flags that change *what* doctor validates, applied on top of config."""
|
||||
overrides: dict = {}
|
||||
model_name, hf_repo = _resolve_model_flags(
|
||||
getattr(args, "model", None), getattr(args, "model_id", None)
|
||||
)
|
||||
if model_name is not None:
|
||||
overrides["model_name"] = model_name
|
||||
overrides["model_hf_repo"] = hf_repo or ""
|
||||
for flag, key in (
|
||||
("quantization", "quantization"),
|
||||
("download_dir", "download_dir"),
|
||||
("shard_start", "shard_start"),
|
||||
("shard_end", "shard_end"),
|
||||
):
|
||||
value = getattr(args, flag, None)
|
||||
if value is not None:
|
||||
overrides[key] = value
|
||||
if getattr(args, "cpu", False):
|
||||
overrides["force_cpu"] = True
|
||||
return overrides
|
||||
|
||||
|
||||
def _cmd_doctor(args) -> int:
|
||||
"""Validate the selected model/shard with a bounded real forward."""
|
||||
import json
|
||||
import traceback
|
||||
|
||||
from .config import DEFAULTS, load_config, merge_cli_overrides
|
||||
from .doctor import (
|
||||
DoctorError,
|
||||
default_report_path,
|
||||
render_result,
|
||||
resolve_selection,
|
||||
run_doctor,
|
||||
write_reports,
|
||||
)
|
||||
|
||||
debug = bool(getattr(args, "debug", False))
|
||||
cfg = load_config() or dict(DEFAULTS)
|
||||
overrides = _doctor_overrides(args)
|
||||
if overrides:
|
||||
cfg = merge_cli_overrides(cfg, **overrides)
|
||||
|
||||
try:
|
||||
selection = resolve_selection(cfg)
|
||||
result = run_doctor(
|
||||
selection,
|
||||
recipe_id=args.recipe,
|
||||
all_recipes=args.all_recipes,
|
||||
)
|
||||
except DoctorError as exc:
|
||||
# Bad input (no model, unknown recipe): there is nothing to report on.
|
||||
if debug:
|
||||
traceback.print_exc()
|
||||
print(f"ERROR: {exc}", file=sys.stderr, flush=True)
|
||||
if exc.hint:
|
||||
print(f" {exc.hint}", file=sys.stderr, flush=True)
|
||||
return 1
|
||||
|
||||
written = write_reports(
|
||||
result.reports,
|
||||
Path(args.report) if args.report else default_report_path(),
|
||||
)
|
||||
|
||||
if args.json:
|
||||
print(json.dumps([r.to_dict() for r in result.reports], indent=2, sort_keys=True))
|
||||
else:
|
||||
print(render_result(result, report_path=written))
|
||||
|
||||
if debug:
|
||||
for item in result.results:
|
||||
if item.error is not None:
|
||||
traceback.print_exception(
|
||||
type(item.error), item.error, item.error.__traceback__
|
||||
)
|
||||
return result.exit_code
|
||||
|
||||
|
||||
def _cmd_start(args) -> int:
|
||||
"""Legacy `start` subcommand — preserves backward compatibility with existing tests."""
|
||||
from .config import DEFAULTS
|
||||
@@ -322,6 +401,7 @@ def main() -> None:
|
||||
" models List supported models\n"
|
||||
" models --browse Browse HuggingFace Hub\n"
|
||||
" config Show current config\n"
|
||||
" doctor Check this node can really run its selected shard\n"
|
||||
),
|
||||
)
|
||||
|
||||
@@ -367,6 +447,40 @@ def main() -> None:
|
||||
# config subcommand
|
||||
subparsers.add_parser("config", help="Show current saved config")
|
||||
|
||||
# doctor subcommand — validate the selected shard with a real forward
|
||||
doctor_cmd = subparsers.add_parser(
|
||||
"doctor",
|
||||
help="Check this node can really run its selected model shard",
|
||||
)
|
||||
# These mirror the top-level selection flags. argparse.SUPPRESS keeps an
|
||||
# unpassed subcommand flag from overwriting the top-level one, so both
|
||||
# `meshnet-node --model X doctor` and `meshnet-node doctor --model X` work.
|
||||
doctor_cmd.add_argument("--model", metavar="MODEL", default=argparse.SUPPRESS,
|
||||
help="Model name or HuggingFace repo ID to validate")
|
||||
doctor_cmd.add_argument("--model-id", metavar="MODEL", default=argparse.SUPPRESS,
|
||||
help="Alias for --model")
|
||||
doctor_cmd.add_argument("--quantization", "-q", default=argparse.SUPPRESS,
|
||||
choices=["bf16", "int8", "nf4", "bfloat16", "auto"],
|
||||
help="Quantization level to validate")
|
||||
doctor_cmd.add_argument("--download-dir", metavar="PATH", default=argparse.SUPPRESS,
|
||||
help="Model download directory")
|
||||
doctor_cmd.add_argument("--shard-start", type=int, metavar="N", default=argparse.SUPPRESS,
|
||||
help="Pin shard start layer")
|
||||
doctor_cmd.add_argument("--shard-end", type=int, metavar="N", default=argparse.SUPPRESS,
|
||||
help="Pin shard end layer")
|
||||
doctor_cmd.add_argument("--cpu", action="store_true", default=argparse.SUPPRESS,
|
||||
help="Validate CPU execution even when a GPU is available")
|
||||
doctor_cmd.add_argument("--debug", action="store_true", default=argparse.SUPPRESS,
|
||||
help="Print the full traceback behind a failure")
|
||||
doctor_cmd.add_argument("--recipe", metavar="ID", default=None,
|
||||
help="Recipe to validate (default: baseline)")
|
||||
doctor_cmd.add_argument("--all-recipes", action="store_true",
|
||||
help="Validate every recipe in the catalogue, not just the selected one")
|
||||
doctor_cmd.add_argument("--report", metavar="PATH", default=None,
|
||||
help="Where to write the capability report JSON")
|
||||
doctor_cmd.add_argument("--json", action="store_true",
|
||||
help="Print the capability report JSON instead of a summary")
|
||||
|
||||
# start subcommand (legacy / backward-compat)
|
||||
start_cmd = subparsers.add_parser("start", help="Start node (legacy flags)")
|
||||
start_cmd.add_argument("--tracker")
|
||||
@@ -406,6 +520,8 @@ def main() -> None:
|
||||
sys.exit(_cmd_models(args))
|
||||
elif args.command == "config":
|
||||
sys.exit(_cmd_config(args))
|
||||
elif args.command == "doctor":
|
||||
sys.exit(_cmd_doctor(args))
|
||||
elif args.command == "start":
|
||||
sys.exit(_cmd_start(args))
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user