A robust model exchange workflow integrates all concepts from previous chapters into a cohesive pipeline that spans training, optimization, versioning, distribution, and deployment.
#!/usr/bin/env python3
"""
Complete model exchange pipeline following WIA-AI-008 standard
弘益人間 - Benefit All Humanity
"""
import torch
import mlflow
import onnx
from datetime import datetime
class ModelExchangePipeline:
def __init__(self, config):
self.config = config
mlflow.set_tracking_uri(config['mlflow_uri'])
mlflow.set_experiment(config['experiment_name'])
def train(self):
"""Phase 1: Train model"""
print("📚 Phase 1: Training model...")
with mlflow.start_run():
# Train model
model = self._train_model()
# Log everything
mlflow.log_params(self.config['hyperparameters'])
mlflow.log_metrics(self.metrics)
mlflow.log_artifact("training_logs.txt")
# Save PyTorch model
torch.save(model.state_dict(), "model.pth")
return model
def optimize(self, model):
"""Phase 2: Optimize model"""
print("⚡ Phase 2: Optimizing model...")
# Quantization
quantized_model = torch.quantization.quantize_dynamic(
model, {torch.nn.Linear}, dtype=torch.qint8
)
# Prune
# ... pruning code ...
# Validate accuracy
accuracy_drop = self._validate_optimization(model, quantized_model)
assert accuracy_drop < 0.02, "Accuracy degradation too high"
return quantized_model
def export(self, model):
"""Phase 3: Export to multiple formats"""
print("📦 Phase 3: Exporting to multiple formats...")
# Export to ONNX
dummy_input = torch.randn(1, *self.config['input_shape'])
torch.onnx.export(
model, dummy_input, "model.onnx",
opset_version=15, export_params=True,
input_names=['input'], output_names=['output'],
dynamic_axes={'input': {0: 'batch'}, 'output': {0: 'batch'}}
)
# Validate ONNX
onnx_model = onnx.load("model.onnx")
onnx.checker.check_model(onnx_model)
# Export to TorchScript
scripted_model = torch.jit.script(model)
scripted_model.save("model.pt")
print("✓ Exported to ONNX and TorchScript")
def create_model_card(self):
"""Phase 4: Create comprehensive model card"""
print("📝 Phase 4: Creating model card...")
model_card = {
'name': self.config['model_name'],
'version': self.config['version'],
'created_at': datetime.now().isoformat(),
'framework': 'pytorch',
'architecture': self.config['architecture'],
'metrics': self.metrics,
'hyperparameters': self.config['hyperparameters'],
'intended_use': 'Image classification',
'limitations': 'Limited to ImageNet classes',
'ethical_considerations': 'May have biases from training data',
'philosophy': '弘益人間 - Benefit All Humanity'
}
with open("model_card.json", "w") as f:
json.dump(model_card, f, indent=2)
def register(self):
"""Phase 5: Register to model registry"""
print("🏛️ Phase 5: Registering to MLflow...")
mlflow.pytorch.log_model(
self.model,
"model",
registered_model_name=self.config['model_name']
)
# Transition to staging
client = mlflow.tracking.MlflowClient()
versions = client.search_model_versions(f"name='{self.config['model_name']}'")
latest_version = versions[0].version
client.transition_model_version_stage(
name=self.config['model_name'],
version=latest_version,
stage="Staging"
)
print(f"✓ Registered version {latest_version}")
def deploy(self):
"""Phase 6: Deploy model"""
print("🚀 Phase 6: Deploying model...")
# Create TorchServe archive
os.system(f"""
torch-model-archiver \\
--model-name {self.config['model_name']} \\
--version {self.config['version']} \\
--serialized-file model.pt \\
--handler image_classifier \\
--export-path model-store/
""")
# Deploy to TorchServe
# ... deployment code ...
print("✓ Model deployed")
def run_pipeline(self):
"""Execute complete pipeline"""
print("=" * 60)
print("WIA-AI-008 Model Exchange Pipeline")
print("弘益人間 - Benefit All Humanity")
print("=" * 60)
model = self.train()
model = self.optimize(model)
self.export(model)
self.create_model_card()
self.register()
self.deploy()
print("\n✅ Pipeline completed successfully!")
# Usage
config = {
'model_name': 'resnet18-classifier',
'version': '1.0.0',
'experiment_name': 'image-classification',
'mlflow_uri': 'http://localhost:5000',
'architecture': 'ResNet-18',
'input_shape': [3, 224, 224],
'hyperparameters': {
'learning_rate': 0.001,
'batch_size': 32,
'epochs': 10
}
}
pipeline = ModelExchangePipeline(config)
pipeline.run_pipeline()
A research team fine-tuned BERT for sentiment analysis and wants to share it with the community following WIA-AI-008 standards.
from transformers import BertForSequenceClassification, BertTokenizer, TrainingArguments, Trainer
from huggingface_hub import HfApi, create_repo
# 1. Fine-tune model
model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
trainer = Trainer(model=model, args=training_args, train_dataset=train_dataset)
trainer.train()
# 2. Save model and tokenizer
model.save_pretrained("./sentiment-bert")
tokenizer.save_pretrained("./sentiment-bert")
# 3. Create comprehensive README (model card)
readme = """---
language: en
license: apache-2.0
tags:
- sentiment-analysis
- bert
- text-classification
datasets:
- imdb
metrics:
- accuracy: 0.934
- f1: 0.931
model-index:
- name: sentiment-bert
results:
- task:
type: text-classification
name: Sentiment Analysis
dataset:
name: IMDB
type: imdb
metrics:
- type: accuracy
value: 0.934
---
# Sentiment Analysis BERT
Fine-tuned BERT-base model for sentiment analysis on IMDB reviews.
## Model Details
- Base model: bert-base-uncased
- Task: Binary sentiment classification (positive/negative)
- Training data: IMDB dataset (50,000 reviews)
- Framework: PyTorch + Transformers
## Usage
```python
from transformers import pipeline
classifier = pipeline('sentiment-analysis', model='username/sentiment-bert')
result = classifier('This movie was amazing!')
# [{'label': 'POSITIVE', 'score': 0.9987}]
```
## Training Procedure
- Learning rate: 2e-5
- Batch size: 16
- Epochs: 3
- Optimizer: AdamW
## Evaluation Results
- Accuracy: 93.4%
- F1 Score: 93.1%
- Precision: 94.2%
- Recall: 92.0%
## Limitations
- English language only
- Trained on movie reviews, may not generalize to other domains
- May exhibit biases present in IMDB dataset
## Ethical Considerations
弘益人間 (Benefit All Humanity) - This model is intended for research and educational purposes.
Users should be aware of potential biases and use responsibly.
## Citation
```bibtex
@misc{sentiment-bert,
author = {Research Team},
title = {Fine-tuned BERT for Sentiment Analysis},
year = {2025},
publisher = {Hugging Face},
howpublished = {\\url{https://huggingface.co/username/sentiment-bert}}
}
```
"""
with open("./sentiment-bert/README.md", "w") as f:
f.write(readme)
# 4. Create repository and upload
repo_id = "username/sentiment-bert"
create_repo(repo_id, exist_ok=True)
api = HfApi()
api.upload_folder(
folder_path="./sentiment-bert",
repo_id=repo_id,
commit_message="Initial model upload"
)
print(f"✓ Model published: https://huggingface.co/{repo_id}")
A company trained YOLOv5 in PyTorch and needed to deploy it on both iOS (CoreML) and Android (TFLite) while maintaining consistent performance.
# PyTorch (Training) → ONNX → TFLite (Android)
# ↓
# CoreML (iOS)
# Step 1: Export PyTorch to ONNX
import torch
from models.yolo import YOLOv5
model = YOLOv5.from_pretrained('yolov5s')
model.eval()
dummy_input = torch.randn(1, 3, 640, 640)
torch.onnx.export(
model, dummy_input, "yolov5s.onnx",
opset_version=12, input_names=['images'],
output_names=['output'], dynamic_axes={'images': {0: 'batch'}}
)
# Step 2: ONNX to CoreML (iOS)
import coremltools as ct
from onnx_coreml import convert
coreml_model = convert(model='yolov5s.onnx')
coreml_model.save('YOLOv5.mlmodel')
# Step 3: ONNX to TensorFlow to TFLite (Android)
from onnx_tf.backend import prepare
import tensorflow as tf
onnx_model = onnx.load("yolov5s.onnx")
tf_model = prepare(onnx_model)
tf_model.export_graph("yolov5_tf")
converter = tf.lite.TFLiteConverter.from_saved_model("yolov5_tf")
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_model = converter.convert()
with open("yolov5s.tflite", "wb") as f:
f.write(tflite_model)
# Step 4: Numerical validation
validate_cross_platform(pytorch_model, coreml_model, tflite_model)
| Platform | Format | Size | Latency | mAP |
|---|---|---|---|---|
| Server (PyTorch) | .pt | 14.4 MB | 8ms (GPU) | 56.0% |
| iOS (CoreML) | .mlmodel | 7.2 MB | 45ms (ANE) | 55.8% |
| Android (TFLite) | .tflite | 7.3 MB | 52ms (GPU) | 55.7% |
A large tech company built a centralized ML platform managing hundreds of models across dozens of teams.
# .gitlab-ci.yml
stages:
- train
- test
- optimize
- register
- deploy
train:
stage: train
script:
- python train.py --config config.yaml
- python validate.py --threshold 0.90
artifacts:
paths:
- model.pth
- metrics.json
test:
stage: test
script:
- pytest tests/test_model.py
- python benchmark.py --latency-threshold 100
dependencies:
- train
optimize:
stage: optimize
script:
- python quantize.py --model model.pth
- python export_onnx.py
- python validate_onnx.py
artifacts:
paths:
- model_quantized.pth
- model.onnx
register:
stage: register
script:
- python register_model.py --name $CI_COMMIT_TAG
only:
- tags
deploy:
stage: deploy
script:
- python deploy_triton.py --version $CI_COMMIT_TAG
when: manual
only:
- tags
| Pitfall | Impact | Solution |
|---|---|---|
| Skipping numerical validation after conversion | Silent accuracy degradation | Always compare outputs with tolerance checks |
| Hardcoding model paths | Difficult to version/deploy | Use configuration files and environment variables |
| No model versioning | Cannot track or rollback | Implement semantic versioning from day 1 |
| Missing model cards | Poor reproducibility | Automate model card generation in pipeline |
| Deploying without monitoring | Production issues go unnoticed | Set up comprehensive monitoring before launch |
| Over-optimizing for speed | Accuracy degradation | Define acceptable accuracy thresholds |
The WIA-AI-008 standard provides a foundation for these future developments, ensuring interoperability, transparency, and ethical deployment of AI models. As the field evolves, the standard will adapt to incorporate new best practices while maintaining its core philosophy of 弘益人間 (Benefit All Humanity).
Model exchange is no longer optional—it's essential for modern ML operations. By following the WIA-AI-008 standard and the best practices outlined in this book, teams can:
The journey from training to production is complex, but with the right tools, processes, and standards, it becomes manageable and repeatable. We hope this book serves as a comprehensive guide for your model exchange needs.
Korea operates a comprehensive standards governance system through inter-ministerial cooperation. National Standards Council (under Prime Minister's Office, per Framework Act on National Standards Article 5) coordinates KATS (Korean Agency for Technology and Standards), MFDS (Ministry of Food and Drug Safety), MOTIE (Ministry of Trade, Industry and Energy), MSIT (Ministry of Science and ICT), MOIS (Ministry of the Interior and Safety), MOE (Ministry of Environment), MOHW (Ministry of Health and Welfare), MND (Ministry of National Defense), MCST (Ministry of Culture, Sports and Tourism), MOFA (Ministry of Foreign Affairs), MOJ (Ministry of Justice), and FSC (Financial Services Commission). Accreditation and Testing: KOLAS (Korea Laboratory Accreditation Scheme) accredits 800+ testing laboratories. KAS (Korea Accreditation System) accredits 50+ certification bodies. KTC (Korea Testing Certification), KTR (Korea Testing & Research Institute), KTL (Korea Testing Laboratory), and KCL (Korea Conformity Laboratories) provide conformance testing. Telecom and Cyber: KCC (Korea Communications Commission), KCA (Korea Communications Agency), TTA (Telecommunications Technology Association), IITP (Institute for Information & Communications Technology Planning & Evaluation), NIPA (National IT Industry Promotion Agency), KISA (Korea Internet & Security Agency), KCMVP (Korea Cryptographic Module Validation Program), NIS (National Intelligence Service), NSR (National Security Research Institute), and NCSC (National Cyber Security Center). National R&D Centers: KIST, ETRI, KAIST, Seoul National University, Yonsei University, Korea University, POSTECH, UNIST, GIST, DGIST, KISTI, KIER, KIMM, KRICT, KFRI, KRIBB. International Standards Cooperation: ISO TC/SC Korean secretariats, IEC TC/SC Korean secretariats, ITU-T Study Group Korean chairs, 3GPP RAN/SA Korean chairs, IEEE 802 Korean chairs, W3C Korea office, OASIS Korea office, IETF Korea cooperation, OECD CSTP, UN ESCAP, APEC SCSC Korean cooperation. Korean Industrial Standards (KS) Catalog: KS X (Information) 25,000+, KS A (Basic) 15,000+, KS B (Machinery) 25,000+, KS C (Electrical) 18,000+, KS D (Metallurgy) 12,000+, KS E (Mining) 5,000+, KS F (Construction) 18,000+, KS H (Food) 8,000+, KS I (Environment) 5,000+, KS J (Biology) 3,000+, KS K (Textile) 15,000+, KS L (Ceramics) 7,000+, KS M (Chemistry) 12,000+, KS P (Medical) 5,000+, KS Q (Quality Mgmt) 4,000+, KS R (Transport) 12,000+, KS S (Service) 3,000+, KS T (Packaging) 4,000+, KS V (Shipbuilding) 5,000+, KS W (Aerospace) 3,000+ — totaling 220,000+ Korean Industrial Standards. Key Acts: Personal Information Protection Act (Act 19234, effective Sept 15, 2024), Electronic Government Act, Electronic Signature Act, Act on Promotion of Information and Communications Network Utilization and Information Protection, Information and Communications Infrastructure Protection Act, Data Industry Act, Public Data Act, AI Framework Act (Act 20212, effective July 2026), Industrial Technology Innovation Promotion Act, Framework Act on Science and Technology — 70+ Korean standardization-related laws.
Korea operates digital transformation through a comprehensive governance system. Digital Government: Digital Platform Government Committee (established September 2022, under the President)·Ministry of the Interior and Safety Digital Government Bureau·e-Government Support Center·Gov.kr·National Citizen Service·KDIS (Korea Digital Information Society)·NIA (National Information Society Agency)·MOIS (Ministry of the Interior and Safety). K-DNS Infrastructure: Korea Internet & Security Agency (KISA) Korea Internet Center·KISA DNS Root Server·KRNIC (Korea Network Information Center)·BGP Korea·National Cyber Security Center (NCSC)·KCC (Korea Communications Commission)·MSIT (Ministry of Science and ICT)·NIA·NIPA. Korean Cloud Infrastructure: KT Cloud·NAVER Cloud (NCloud)·Samsung SDS Cloud·LG U+ Cloud·NHN Cloud·Kakao Enterprise Cloud·SK Telecom Cloud·KISA Cloud Security Assurance Program (CSAP)·KCMVP-validated cloud·ISMS-P (Information Security & Personal Information Management System). Korean Security Certifications: KISA ISMS-P certification·KCMVP (Korean Cryptographic Module Validation Program)·NIS (National Intelligence Service) "National Cryptographic Technology Operation Standards"·NCSC "National Cyber Security Strategy 2024-2028"·CC (Common Criteria) Korean evaluation bodies·EAL4·EAL5·KS X ISO/IEC 15408·19790·24759 Korean Profile. Korean Data Standards: NIA AI Hub·National Data Standardization Committee·Statistics Korea (KOSTAT)·MyData 4 Designated Combination Specialists (Samsung SDS, KICI, KOSTAT, KFTC)·National Institute of Korean Language·National Law Information Center·National Spatial Information Platform·National Spatial Data Center·Korean Spatial Information Standards. Finance and Fintech Standards: FSC (Financial Services Commission)·FSS (Financial Supervisory Service)·FIU (Financial Intelligence Unit)·BOK (Bank of Korea)·FSEC (Financial Security Institute)·KFTC (Korea Financial Telecommunications)·KSD (Korea Securities Depository)·KRX (Korea Exchange) 8-agency cooperation. 5G/6G Communications Infrastructure: 5G subscribers 35 million (2024)·5G base stations 350,000·6G commercialization target 2028·5G dedicated networks 16 operators·6G Acceleration Council (MSIT, 2024). K-Content: KOCCA (Korea Creative Content Agency)·MCST (Ministry of Culture, Sports and Tourism)·KCA (Korea Communications Agency)·Korea Culture Information Service Agency·Korean Film Archive·Korea Publishing Industry Promotion Agency. Data 3 Acts (Personal Information Protection Act·Credit Information Act·Telecommunications Network Act, 2020 enforcement)·Data Industry Act (2021)·Public Data Act (2013)·AI Framework Act (2026)·Digital Platform Government Framework Act (2024 proposed) — Korea digital transformation core legislation.