Deployment
This guide covers how to deploy pre-trained machine learning models to the ViewAI platform.
Overview
The ViewAI SDK supports deploying externally trained models (scikit-learn, XGBoost, etc.) to the ViewAI platform for hosting and inference. The deployment process includes:
Model serialization (ONNX or Pickle)
Schema generation and validation
File upload to cloud storage
Model registration and hosting
Quick Start
from viewai_client import ViewAIClient
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
# Train your model
model = RandomForestClassifier()
model.fit(X_train, y_train)
# Initialize ViewAI client
client = ViewAIClient(api_key="your-api-key")
workspace = client.retrieve_default_workspace()
# Create deployable model
deployable = client.create_deployable_model(
model=model,
dataset=train_df,
target_column="target",
model_name="My Classifier",
workspace=workspace
)
# Deploy to ViewAI
dashboard_id = deployable.deploy()
print(f"Model deployed: {dashboard_id}")Deployment Workflow
Complete Deployment Example
Model Serialization
The ViewAI SDK supports two serialization formats:
ONNX Format (Recommended)
ONNX (Open Neural Network Exchange) provides version-agnostic, cross-platform model deployment:
ONNX Benefits:
Version-agnostic (works across Python versions)
Cross-platform compatibility
Optimized inference performance
Smaller model size
ONNX Requirements:
Pickle Format (Legacy)
Pickle format for Python-specific deployment:
Pickle Limitations:
Python version-specific
Not cross-platform
Larger file size
Security concerns
Supported Model Types
The SDK supports most scikit-learn compatible models:
Deploying Pipelines
Deploy complete scikit-learn pipelines:
Schema Management
Schemas define the expected input format and constraints for model inference.
Automatic Schema Generation
Schemas are automatically generated from your training data:
Using ModelSchemaManager
Create and customize schemas manually:
Customizing Schema Fields
Update Categorical Fields
Define allowed categories for categorical features:
Update Numerical Ranges
Set min/max constraints for numerical features:
Update Field Types
Change the data type for schema fields:
Schema Validation
Validate input data against schema before deployment:
Schema Preview and Export
Preview and export schemas for documentation:
Deploying Models
Basic Deployment
Deploy a model with default settings:
Deployment with Project Context
Organize models by project:
Deployment Progress
The deployment process shows progress:
Handling Deployment Failures
Handle deployment errors:
Deployment Validation
Testing Deployed Models
Test your deployed model immediately after deployment:
Automated Validation Pipeline
Create an automated validation pipeline:
Comparing Model Versions
Compare predictions between local and deployed models:
Production Patterns
Versioned Model Deployment
Deploy models with proper versioning:
Blue-Green Deployment
Implement blue-green deployment pattern:
Deployment with Rollback
Implement deployment with rollback capability:
A/B Testing Deployment
Deploy multiple model versions for A/B testing:
Troubleshooting
ONNX Conversion Errors
If ONNX conversion fails:
Schema Errors
Handle schema-related errors:
Upload Failures
Handle file upload issues:
See Also
Training Models - Train models on ViewAI platform
Making Predictions - Use deployed models for inference
Schema Management - Advanced schema customization
API Reference - Model class documentation
Was this helpful?