Two-phase workflow: run GridSearchCV on SVC with digits data, persist the cv_results_, then reload to find best params and refit for test evaluation.
harbor run -t vmax-modal/modal-port-v1-patched-cv-results-persistharbor download vmax-modal/modal-port-v1-patched-cv-results-persistYou are given a Python workflow that runs GridSearchCV to tune an SVC on the digits dataset, serializes the cross-validation results, then reloads those results to refit the best model and evaluate on a held-out test set. Your task is to port this workflow to Modal so that the grid search and the final evaluation run as separate cloud functions with results persisted in a Modal Volume.
The workflow has two phases:
Phase 1 – Grid Search and Serialize:
n_class classes and split into train/test sets.GridSearchCV over SVC(kernel='rbf') with parameter grid {'C': [0.1, 1, 10], 'gamma': [0.001, 0.01]} and 3-fold CV.cv_results_ dictionary to bytes using joblib.Phase 2 – Deserialize, Refit, and Evaluate:
cv_results_ from bytes.run_workflow receives a case dict with these keys:
| Key | Type | Description |
|---|---|---|
n_class |
int | Number of digit classes to include |
test_size |
float | Fraction of data held out for testing |
random_state |
int | Global random seed |
Return a dict with:
| Key | Type | Description |
|---|---|---|
best_C |
float | Best C value found by grid search |
best_gamma |
float | Best gamma value found by grid search |
best_cv_score |
float | Best mean cross-validation score |
test_accuracy |
float | Test accuracy of the refitted model |
n_cv_results |
int | Number of parameter combinations evaluated |
When porting to Modal, the grid search phase and the evaluation phase should be separate remote functions. The grid search is inherently parallel across parameter combinations—in Modal each combination can run as a separate mapped function call. The serialized cv_results_ should be written to a Modal Volume between phases.
Modal concepts to use:
scikit-learn, joblib) must be declared as image dependencies.Write the solution in /app/solution/modal_app.py. Define a Modal application
object named app and expose a callable named run_case that accepts one case
dictionary and returns a JSON-serializable result matching the original
workflow.
The finalized task workspace is copied into /app when the sandbox starts.
Source files from environment/workspace are available at paths such as
/app/workflow.py, /app/original_workflow.py, /app/original.py, or other
task-specific filenames.
Expose the workflow as a single Modal remote function: define run_case as an @app.function so the harness can invoke it with run_case.remote(case).
The solution must also use: