feat: move input coercion & output encoding to Rust, delete dead SDK modules#2783
Merged
tempusfrangit merged 5 commits intomainfrom Feb 27, 2026
Merged
feat: move input coercion & output encoding to Rust, delete dead SDK modules#2783tempusfrangit merged 5 commits intomainfrom
tempusfrangit merged 5 commits intomainfrom
Conversation
…adt/_inspector Replace the Python-side input validation (_inspector.check_input) and output encoding (cog.json/cog.files) with pure Rust implementations in coglet-python: input.rs: - Remove Runtime/InputProcessor/CogInputProcessor architecture - Add prepare_input() with detect_file_fields() for File vs Path annotation introspection and coerce_url_strings() for URL->Path/File conversion - Input validation now happens at HTTP edge (InputValidator); worker only does URL coercion and file downloads output.rs: - Pure Rust make_encodeable() handles Pydantic models, dataclasses, enums, datetime, numpy types, and collections - Pure Rust encode_files() converts Path/IOBase to base64 data URLs - No longer calls cog.json.make_encodeable or cog.files.upload_file predictor.rs: - Remove runtime/input_processor fields - Add predict_func()/train_func() getters for type annotation introspection - Add unwrap_field_info_defaults() to patch FieldInfo wrapper objects in __defaults__/__kwdefaults__ so Python resolves actual default values - Use input::prepare_input(py, dict, &func) directly
Remove 20 Python files (-3,071 lines) whose functionality has moved to
Rust in coglet-python (input coercion, output encoding, schema generation,
file uploads, logging, config parsing).
Deleted modules:
_adt, _inspector, _schemas, coder, coders/*, command/*,
config, errors, exceptions, files, json, logging, mode,
schema, suppress_output
Simplified:
- input.py: remove Representation base, mutable default auto-conversion,
default_factory support (now raises TypeError)
- predictor.py: remove get_predict/get_train/wait_for_env/get_healthcheck
- server/http.py: read predictor ref from env vars instead of cog.yaml,
remove structlog/logging setup
- types.py: remove ExperimentalFeatureWarning
- __init__.py: remove Coder imports, import CancelationException from coglet
- test_input.py, test_model.py: updated for new behavior
1f89033 to
5560081
Compare
markphelps
reviewed
Feb 27, 2026
Co-authored-by: Mark Phelps <[email protected]> Signed-off-by: Morgan Fainberg <[email protected]>
… file_to_base64) Cover primitives, collections, enums, datetime, dataclasses, generators, nested structures, PathLike->base64, IOBase->base64, MIME guessing, seek-to-start, dict/list recursion, and end-to-end process_output. All tests use stdlib Python only (no cog import needed).
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
_adt.pyand_inspector.pyBasePredictor,Input, types, andBaseModelCommit 1: Rust coercion (
input.rs,output.rs,predictor.rs)input.rs— ReplacedRuntime/InputProcessor/CogInputProcessorarchitecture withprepare_input(py, input, func):detect_file_fields()— introspects type annotations forcog.File/cog.Pathparams (handlesOptional,list[File],Union[File, None])coerce_url_strings()— converts URL strings toPath.validate()orFile.validate()based on annotationsdownload_url_paths_into_dict()— parallelURLPathdownloads viaThreadPoolExecutoroutput.rs— Pure Rust output processing replacingcog.json.make_encodeable()+cog.files.upload_file():make_encodeable()— handles Pydantic v1/v2, dataclasses, enums, datetime, numpy,PathLike, collectionsencode_files()— recursivePath/IOBase→ base64 data URL conversionfile_to_base64()— MIME type guessing, seek-to-start, base64 encodingpredictor.rs— Removedruntime/input_processorfields:predict_func()/train_func()— getters for type annotation introspectionunwrap_field_info_defaults()— patches__defaults__/__kwdefaults__to replaceFieldInfo(default=42)wrappers with actual valuesCommit 2: SDK cleanup
Deleted modules:
_adt,_inspector,_schemas,coder,coders/*,command/*,config,errors,exceptions,files,json,logging,mode,schema,suppress_outputSimplified:
input.py— removedRepresentation, mutable default auto-conversion;default_factorynow raisesTypeErrorpredictor.py— removedget_predict/get_train/wait_for_env/get_healthcheckserver/http.py— reads predictor ref fromCOG_PREDICT_TYPE_STUB/COG_TRAIN_TYPE_STUBenv vars, removed structlog/configtypes.py— removedExperimentalFeatureWarning__init__.py— removedCoderimports,CancelationExceptionnow fromcogletTesting
#[ignore]— require cog in PYTHONPATH)