Repository navigation
feat: mlproject run options and chapkit mlproject export (CLIM-1435) - #141
Merged
Merged
Conversation
…-level to mlproject run (CLIM-1435) Name the artifact hierarchy after the MLproject instead of always mlproject, matching the services mlproject migrate and init generate.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
….py (CLIM-1435) The reverse of mlproject migrate: reads the service info, config class, shell runner and artifact hierarchy from a service module and writes the MLproject that mlproject run serves as the same service. --check fails when the file is stale or would be read back as a different service.
- export keeps a reserved config field whose constraints changed, even with the default unchanged, and --check compares what each option accepts - export escapes literal braces for both format passes mlproject run applies - --database keeps configs and trained models; job history stays in memory, so the help and docs no longer promise it
mortenoh
commented
Oct 15, 2026
mortenoh
left a comment
Contributor
Author
There was a problem hiding this comment.
Tried this against chapkit_ghr_model (chap-models/chapkit_ghr_model#10). No blocking bugs; the new options work as described.
Verified
chapkit mlproject exporton chapkit_ghr_model'smain.pywrites an MLproject that passes--check. Against the committed MLproject the only differences are the header and the position of onedescriptionkey, as the description says.mlproject run proj --config-format flat --database state/c.db --log-level warning: the startup output shows the layout and storage path, and nothing is written toproj/.--databasepersistence: a config created withn_samples: 100is still there after restarting on the same file.- Without
--database, storage stays in memory, the same as the builder default.
Issues
--config-formatcannot be reached fromchap eval. chap-core's--run-config.as-chapkitstartschapkit mlproject run .with fixed arguments, and the-cliimages startchapkit run .the same way, so anything run that way still gets the nested layout. For that path the layout has to be in the MLproject itself, for example a top-levelconfig_format: flatthat the CLI flag can override. Export could then write that key instead of the header comment ("run with--config-format flat"). Until then, scripts written for a flatmain.pyservice have to accept both layouts.- Export silently drops settings an MLproject cannot carry, and
--checkstill passes. The one that changes behaviour is the runner validation hooks (on_validate_train/on_validate_predict): data themain.pyservice rejects is accepted by the MLproject service. Also dropped:with_authAPI keys, custom health checks or extra routes, custom artifactlevel_labels, and the keepalive interval set inwith_registration. Suggest at least a warning for each, and perhaps a--checkfailure for validation hooks. --log-leveldoes not cover the first log lines. With--log-level warning, the three lines logged while the app is built (shell_runner_initialized,monitoring.enabled,app.mounted) still print at info, because servicekit only appliesLOG_LEVELonce the app starts. Request logs do respect it.- Export executes the module, side effects included. chapkit_ghr_model's
main.pycreatesdata/and builds the whole app with monitoring. The PR describes how the module is loaded; the docs should say plainly that export runs it. - A
--databasefile inside the project stays out of train/predict workspaces only because of its extension.WORKSPACE_EXCLUDE_PATTERNScovers*.db/*.sqlite*, but a path such asstate/chapkitwith no extension is copied into every workspace. A warning or a note in the docs would cover it.
…ress review (CLIM-1435) - mlproject run, migrate and export use meta_data.config_format, so the layout reaches chap eval and the -cli images; chap-core ignores unknown meta_data keys but rejects unknown top-level ones. --config-format still overrides it. - export warns about settings an MLproject cannot carry: validation hooks, custom level labels, API key auth and extra routes - --log-level applies before the service is built - warn when a --database file inside the project would be copied into every workspace - docs say plainly that export runs the module
mortenoh
commented
Oct 15, 2026
mortenoh
left a comment
Contributor
Author
There was a problem hiding this comment.
Re-tested 98d5253 against chapkit_ghr_model. All five points from the previous review are addressed.
Verified
meta_data.config_format: export writesconfig_format: flatfor a flat runner;mlproject runwith no flags reports the flat layout, and--config-format chap_coreoverrides it. chap-core'sModelTemplateConfigV2loads the exported file and ignores the key, so older chap-core versions are unaffected.- Export warnings: chapkit_ghr_model's
main.pyhas no validation hooks, auth, custom level labels or extra routes, and gets no warnings. --log-level warning: no info lines at all now.--database proj/state/chapkitwarns about the workspace copy;proj/state/chapkit.dbdoes not.- A fresh export of chapkit_ghr_model passes
--check. - MLproject, export and migrate tests pass locally (222).
Remaining
- Keepalive interval is still dropped silently. chapkit_ghr_model's
main.pyuseswith_registration(keepalive_interval=15), and export does not warn thatmlproject runfalls back to the default. Minor, but it would fit with the otherdropped_settingswarnings (and--keepalive-intervalexists to restore it). chap eval --run-config.as-chapkitonly benefits once chap-core depends on a chapkit release with this PR. It runs the chapkit installed alongside chap-core (currently 2.3.1, which ignoresmeta_data.config_format). Worth a chap-core dependency bump after release.
… (CLIM-1435) ServiceBuilder.build records the registration options on app.state, so export can compare the keepalive interval with servicekit's default.
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-ups from adding an MLproject to chapkit_ghr_model (chap-models/chapkit_ghr_model#10), in two parts.
chapkit mlproject run: settings a hand-writtenmain.pyservice hasmeta_data.config_format: chap_core|flatin the MLproject, overridable with--config-format: layout of theconfig.ymlthe scripts read. Default stayschap_core(options nested underuser_option_values, as chap-core does);flatsuits scripts written for amain.pyservice. It lives in the MLproject so it reacheschap eval --run-config.as-chapkitand the-cliimages, which startchapkit mlproject run .with fixed arguments. It goes undermeta_databecause chap-core's MLproject model isextra="forbid"at the top level (verified: a top-level key is rejected, an unknownmeta_datakey is ignored).mlproject migratehonours it too.--database PATH: keep configs and trained models (artifacts) in a SQLite file so they survive a restart, and predict works on a model trained before it. Job history is not persisted: the job scheduler is in memory, so/api/v1/jobsstarts empty after a restart. Takes a plain file path, no SQLAlchemy URL. The file and its directory are created if missing, migrations run on startup, and a relative path is relative to where the command runs (it is resolved before the service changes into the project directory). Without it, state stays in memory as before. A database file inside the project that the workspace copy would not skip (no.db/.sqlite*extension) gets a startup warning.--keepalive-interval SECONDS: keepalive interval once registered with chap-core. Left to servicekit's default (10s) when not given; a warning is printed when it is set without an orchestrator.--log-level: sets both servicekit's structured logging (LOG_LEVEL) and uvicorn, applied before the service is built so it also covers the build-time log lines. Defaults toLOG_LEVEL, theninfo.name(as a Python identifier, the same helpermlproject migrateuses) instead of alwaysmlproject. State is in memory by default, so no stored artifacts carry the old name.Considered and left out:
--workers(the in-memory scheduler cannot be shared between processes), a registration key flag (kept env-only so the secret stays out of the process list), and--max-concurrency(SQLite write locking is why the default is 1).chapkit mlproject export: generate an MLproject frommain.pyThe reverse of
mlproject migrate, moved into chapkit from chapkit_ghr_model'stools/mlproject.py, which imported chapkit internals (RUNNER_PLACEHOLDERS,translate_to_runner_template,build_config_schema) a model repo should not depend on.MLServiceInfo, theBaseConfigsubclass, theShellModelRunnerand theArtifactHierarchyin the module by type, so names do not matter (--config NAMEwhen there are several config classes). Function runners are rejected with a clear error.meta_data,user_options(JSON Schema per field, enum$refs inlined,default_factorydefaults resolved, BaseConfig's reserved fields only when their default or what they accept changes),adaptersand the entry points with runner placeholders turned back into MLproject parameters. Literal braces are escaped for bothstr.formatpassesmlproject runapplies.--checkwrites nothing and fails when the file is stale (prints a diff), or when chapkit's own MLproject reader would serve a different/api/v1/info, config options, defaults or accepted values, commands or adapters.--force.__pycache__left behind); what it prints while building the app goes to stderr, so--checkoutput stays clean.config.yml, export writesmeta_data.config_format: flat, and--checkcompares the layout.--check, without failing) about settings an MLproject cannot carry: runner validation hooks, custom artifact level labels,with_auth, a non-default keepalive interval inwith_registration(with the--keepalive-intervalto restore it), and routes the MLproject service would not serve. Custom health checks cannot be detected and are documented instead. To see the keepalive interval,ServiceBuilder.build()now records the registration options onapp.state.registration_options.Against chapkit_ghr_model's
main.py, the export matches its committed MLproject apart from the header and the position of onedescriptionkey, and--checkpasses.Docs: a Service Options section in
mlproject-runner.mdand a newmlproject-export.mdguide.Follow-up
chap eval --run-config.as-chapkitruns the chapkit installed alongside chap-core (2.3.1 today), which ignoresmeta_data.config_format. Bump chap-core's chapkit dependency once this is released.Test plan
make lintmake test(1085 passed)mkdocs build --strictrun_app, an unknown--config-formatrejected.build_mlproject_appgives the same info and config defaults as the module;--checkpasses fresh, fails stale with a diff, fails on semantic drift (missingauthor_note) and without a file;--force,--output,MLproject.yaml,--config, a changedprediction_periodsdefault, hierarchy/id fallback, function runner, import failure and missing module; constraints on a reserved field kept and enforced, a description-only change still omitted,--checkcatching an option that accepts different values, and commands with literal braces producing the same final command after both format passes.chapkit mlproject run proj --config-format flat --database state/chapkit.db, trained, restarted, artifact still listed with hierarchysmoke_model, nothing written toproj/.chapkit mlproject exportand--checkagainst chapkit_ghr_model'smain.py; the export validates with chap-core's ownModelTemplateConfigV2.chapkit mlproject run --log-level warningprints no info lines.Jira: CLIM-1435