ModelHub Adaptation Agent
This repository is packaged for the ModelHub XC agent platform.
Platform Contract
- Root-level
Dockerfile - Listens on port
8080 - Exposes
GET /health - Handles
SIGTERM - Reads platform-provided
STRATEGY_IDand attaches it to task submissions asstrategyId
The root main.py starts a lightweight health server and runs the existing
submission poller in a child process.
Runtime Environment
The image includes multi-account ModelHub and ModelScope token fallbacks for the agent platform. Environment variables can override them without rebuilding the image.
MODELHUB_XC_TOKEN,XC_TOKEN,XC_TOKEN2..., orMODELHUB_XC_TOKENSfor ModelHub API authenticationMODELHUB_JWT_TOKENorJWT_TOKENcan be used instead when the platform provides a JWTMODELSCOPE_API_TOKENorMODELSCOPE_TOKENoptional override for the embedded ModelScope fallback tokenSTRATEGY_IDis expected to be injected by the ModelHub agent platform and is attached to submissions for strategy attribution; it is not an API authentication token
Optional tuning:
MODELHUB_AGENT_POLL_INTERVAL_SECONDSdefault15MODELHUB_AGENT_IDLE_INTERVAL_SECONDSdefault60MODELHUB_AGENT_POST_CYCLE_COOLDOWN_SECONDSdefault2MODELHUB_AGENT_MAX_SUBMITS_PER_RUNdefault0(fill all currently available slots)MODELHUB_AGENT_ACTIVE_TASK_CAPdefault100per accountMODELHUB_CAPACITY_PROBE_INTERVAL_CYCLESdefault3MODELHUB_CAPACITY_STATE_PATHdefault.modelhub_state/account_capacity.jsonMODELHUB_AGENT_ACTIVE_COUNTS_TTL_SECONDSdefault15MODELHUB_AGENT_RESERVATION_TTL_SECONDSdefault120MODELHUB_AGENT_INSTANCE_IDoptional stable worker identity used to spread concurrent agents across accounts and candidatesMODELHUB_AGENT_CLAIMS_PATHdefault.modelhub_state/submission_claims.jsonlMODELHUB_AGENT_DAILY_TARGETMODELHUB_AGENT_MIN_DOWNLOADSMODELHUB_AGENT_GPUSMODELHUB_AGENT_EXTRA_ARGSMODELHUB_GPU_STRATEGY_STATE_PATHdefault.modelhub_state/gpu_strategy.jsonMODELSCOPE_PAGE_INTERVAL_SECONDSdefault0.25MODELSCOPE_PAGE_CACHE_TTL_SECONDSdefault900
Adaptive GPU Strategy
When no explicit GPU override is supplied, the worker uses a local 50/30/20 strategy generation:
- 50%: the three long-term GPUs with the best Wilson lower confidence score and at least 100 terminal samples
- 30%: round-robin exploration across every currently supported GPU
- 20%: the best GPU among the latest 1,000 terminal tasks
Only platform-accepted tasks count. After exactly 200 accepted tasks, the next
poll cycle reloads all account history, generates a new immutable strategy snapshot,
and resets the generation counters to 100/60/40 targets. The active snapshot and
progress are stored in .modelhub_state/gpu_strategy.json.
ModelScope HTTP 429 responses use exponential backoff and Retry-After. Successful
pages remain cached, so a later cycle retries the failed page instead of restarting
the whole pagination scan.
Concurrent Agents
The token pool keeps a local reservation for every in-flight submission, so a lagging platform count cannot send all concurrent requests to the same account. If another process fills an account first, the submission is retried immediately against another account with capacity.
Workers that share a filesystem also coordinate model/GPU claims through
.modelhub_state/submission_claims.jsonl. Workers in isolated containers use
different candidate ordering (derived from STRATEGY_ID, instance ID, or
hostname), which reduces duplicate work while the platform remains the final
authority for account capacity and model/GPU uniqueness.
If the platform reports that a model/GPU is already being validated, the claim
is retained and the runner immediately draws replacement candidates from the
same scan instead of retrying the duplicate every cycle. Startup logs and the
health response expose agent_version; version 2026.08.02.3 or newer includes
this behavior.
Deploy
Create a tag and submit the repository URL plus tag in "我的适配智能体".
git tag agent-v6
git push origin agent-v6