2026-10-16 22:00:52 +08:00
|
|
|
"""Dry-run configuration: token-resolvable build-config first; failures fall back to sample with GAP."""
|
2026-10-16 19:00:15 +08:00
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from src.build_config_client import build_config, BuildConfigError
|
|
|
|
|
from src.task_add_client import resolve_token
|
|
|
|
|
|
2026-10-16 22:00:52 +08:00
|
|
|
SOURCE = 'POST /api/adapt/task/build-config (discovered via capture); fallback templates/config_params.sample.yaml'
|
|
|
|
|
GAP = 'GAP: build-config API discovered via capture; sample is dry-run draft only, NOT production-ready. API foothold evidence: GAP (not wired).'
|
|
|
|
|
GPU_ENUMS = {
|
|
|
|
|
'壁砺': 'Biren_166m', '壁砺166M': 'Biren_166m', 'Biren_166m': 'Biren_166m',
|
|
|
|
|
'曦望': 'Sunrise_pt-200-x1', '曦望 S2': 'Sunrise_pt-200-x1',
|
|
|
|
|
'Sunrise_pt-200-x1': 'Sunrise_pt-200-x1',
|
|
|
|
|
}
|
2026-10-16 19:00:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def config_params_source():
|
2026-10-16 22:00:52 +08:00
|
|
|
"""Requested source preference for dry-run.
|
|
|
|
|
|
|
|
|
|
- CONFIG_PARAMS_SOURCE=sample → force offline sample
|
|
|
|
|
- CONFIG_PARAMS_SOURCE=build-config → force API path (with soft fallback in with_meta)
|
|
|
|
|
- default (empty): prefer build-config when resolve_token() succeeds; else sample
|
|
|
|
|
- ALLOW_BUILD_CONFIG=1 remains a legacy opt-in synonym when source empty and token ok
|
|
|
|
|
"""
|
2026-10-16 19:00:15 +08:00
|
|
|
source = os.environ.get('CONFIG_PARAMS_SOURCE', '').strip()
|
|
|
|
|
if source not in ('', 'sample', 'build-config'):
|
|
|
|
|
raise BuildConfigError('unsupported CONFIG_PARAMS_SOURCE')
|
2026-10-16 22:00:52 +08:00
|
|
|
if source:
|
|
|
|
|
return source
|
|
|
|
|
try:
|
|
|
|
|
resolve_token()
|
|
|
|
|
except (ValueError, OSError):
|
|
|
|
|
return 'sample'
|
|
|
|
|
# Token resolvable → prefer build-config (kickoff select-opt default).
|
|
|
|
|
return 'build-config'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_config_params_with_meta(gpu_type=None, framework='vllm', task_type='text-generation'):
|
|
|
|
|
"""Return (YAML, metadata); API failures explicitly fall back for dry-run.
|
|
|
|
|
|
|
|
|
|
scripts/build_config_dry.py calls build_config directly and remains strict.
|
|
|
|
|
"""
|
|
|
|
|
source = config_params_source()
|
|
|
|
|
meta = {'configParams_source': 'sample'}
|
|
|
|
|
try:
|
|
|
|
|
resolve_token()
|
|
|
|
|
except (ValueError, OSError):
|
|
|
|
|
meta['auth'] = 'missing'
|
|
|
|
|
else:
|
|
|
|
|
meta['auth'] = 'ok'
|
|
|
|
|
gpu_enum = GPU_ENUMS.get(gpu_type)
|
|
|
|
|
if source == 'build-config' and gpu_enum is None:
|
|
|
|
|
meta['configParams_fallback_reason'] = 'GAP: gpu enum unmapped'
|
|
|
|
|
elif source == 'build-config':
|
2026-10-16 19:00:15 +08:00
|
|
|
try:
|
2026-10-16 22:00:52 +08:00
|
|
|
yaml = build_config(gpu_enum, framework, task_type)
|
|
|
|
|
except BuildConfigError as error:
|
|
|
|
|
meta['configParams_fallback_reason'] = 'GAP: ' + error.error_attribution
|
2026-10-16 19:00:15 +08:00
|
|
|
else:
|
2026-10-16 22:00:52 +08:00
|
|
|
meta['configParams_source'] = 'build-config'
|
|
|
|
|
return yaml, meta
|
|
|
|
|
return (Path(__file__).resolve().parents[1] / 'templates/config_params.sample.yaml').read_text(), meta
|
2026-10-16 19:00:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_config_params(gpu_type=None, framework='vllm', task_type='text-generation'):
|
2026-10-16 22:00:52 +08:00
|
|
|
"""Compatible YAML-only dry-run wrapper, including explicit fallback."""
|
|
|
|
|
return build_config_params_with_meta(gpu_type, framework, task_type)[0]
|