From 80c41228c2c3f051c0ec83c71a06bc9f4e9d79dd Mon Sep 17 00:00:00 2001 From: Yi Yan Date: Fri, 1 Aug 2025 20:52:55 +0800 Subject: [PATCH 1/5] fix: development build --- .github/workflows/generate-model-config.yml | 131 ++ docs/en/index.md | 1 + docs/en/model-generator.html | 1397 +++++++++++++++++++ tests/generate_model_config.py | 354 +++++ 4 files changed, 1883 insertions(+) create mode 100644 .github/workflows/generate-model-config.yml create mode 100644 docs/en/model-generator.html create mode 100644 tests/generate_model_config.py diff --git a/.github/workflows/generate-model-config.yml b/.github/workflows/generate-model-config.yml new file mode 100644 index 00000000..f7730e62 --- /dev/null +++ b/.github/workflows/generate-model-config.yml @@ -0,0 +1,131 @@ +name: Generate Model Configuration + +on: + push: + branches: [ main ] + paths: + - 'src/emd/models/**' + - 'tests/generate_model_config.py' + pull_request: + branches: [ main ] + paths: + - 'src/emd/models/**' + - 'tests/generate_model_config.py' + workflow_dispatch: # Allow manual trigger + +jobs: + generate-config: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Cache pip dependencies + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt', '**/pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + # Install from pyproject.toml if it exists + if [ -f pyproject.toml ]; then + pip install -e . + elif [ -f requirements.txt ]; then + pip install -r requirements.txt + fi + # Install additional dependencies that might be needed + pip install pathlib datetime + + - name: Create docs directory + run: | + mkdir -p docs + + - name: Run model configuration generator + run: | + cd ${{ github.workspace }} + python tests/generate_model_config.py + env: + PYTHONPATH: ${{ github.workspace }}/src + + - name: Check if model config was generated + run: | + if [ -f docs/model_config.js ]; then + echo "āœ… Model configuration file generated successfully" + echo "File size: $(wc -c < docs/model_config.js) bytes" + echo "Lines: $(wc -l < docs/model_config.js)" + # Show first few lines for verification + echo "First 10 lines of generated file:" + head -10 docs/model_config.js + else + echo "āŒ Model configuration file was not generated" + exit 1 + fi + + - name: Commit and push changes + if: github.event_name != 'pull_request' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + if [ -n "$(git status --porcelain docs/model_config.js)" ]; then + git add docs/model_config.js + git commit -m "šŸ¤– Auto-update model configuration + + - Generated from EMD Python model definitions + - Updated at: $(date -u '+%Y-%m-%d %H:%M:%S UTC') + - Triggered by: ${{ github.event_name }} + - Commit: ${{ github.sha }}" + + git push + echo "āœ… Model configuration updated and committed" + else + echo "ā„¹ļø No changes to model configuration" + fi + + - name: Upload model config as artifact + uses: actions/upload-artifact@v3 + with: + name: model-config + path: docs/model_config.js + retention-days: 30 + + - name: Generate summary + run: | + echo "## šŸ“Š Model Configuration Generation Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + if [ -f docs/model_config.js ]; then + echo "āœ… **Status**: Successfully generated" >> $GITHUB_STEP_SUMMARY + echo "šŸ“ **Output**: \`docs/model_config.js\`" >> $GITHUB_STEP_SUMMARY + echo "šŸ“ **Size**: $(wc -c < docs/model_config.js) bytes" >> $GITHUB_STEP_SUMMARY + echo "šŸ“„ **Lines**: $(wc -l < docs/model_config.js)" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + # Extract model count from the generated file if possible + if grep -q "getModelCount" docs/model_config.js; then + echo "šŸŽÆ **Generated**: Model configuration with helper functions" >> $GITHUB_STEP_SUMMARY + fi + + echo "" >> $GITHUB_STEP_SUMMARY + echo "### šŸ“‹ Generated Configuration Includes:" >> $GITHUB_STEP_SUMMARY + echo "- šŸ¤– Model definitions and metadata" >> $GITHUB_STEP_SUMMARY + echo "- šŸ–„ļø Instance type specifications" >> $GITHUB_STEP_SUMMARY + echo "- āš™ļø Engine configurations" >> $GITHUB_STEP_SUMMARY + echo "- šŸ”§ Service definitions" >> $GITHUB_STEP_SUMMARY + echo "- šŸ› ļø JavaScript helper functions" >> $GITHUB_STEP_SUMMARY + else + echo "āŒ **Status**: Generation failed" >> $GITHUB_STEP_SUMMARY + echo "Please check the workflow logs for details." >> $GITHUB_STEP_SUMMARY + fi \ No newline at end of file diff --git a/docs/en/index.md b/docs/en/index.md index 93fd9f54..db6f25d8 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -45,5 +45,6 @@ For a complete list, see [Supported Models](supported_models.md). - [Quick Start](installation.md) - [CLI Commands](commands.md) - [API Documentation](api.md) +- [Model Generator](model-generator.html) - Interactive tool to explore and configure models - [Best Deployment Practices](best_deployment_practices.md) - [Architecture Overview](architecture.md) diff --git a/docs/en/model-generator.html b/docs/en/model-generator.html new file mode 100644 index 00000000..2d581aa7 --- /dev/null +++ b/docs/en/model-generator.html @@ -0,0 +1,1397 @@ + + + + + + EMD Model Deploy Command Generator + + + +
+ +
+
+

Model Deploy CommandLine Generator

+
+ Loading models... +
+
+
+ + + + + + + + + + + + + + + + + +
Model IDTypeDescriptionInstancesEnginesServicesChina
+ Loading models... +
+
+
+
+ + +
+ +
+ +
+
+ +
+ +
+
+
+ + + +
+
+ + +
+ +
+ + +
+
+ +
+
+ + +
+ +
+ + +
+
+ +

Extra Parameters

+ +
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+ +
+ +
+
+ +
+ + +
+
+
+ + +
+
+
+
+ No models configured yet. Add models from the left panel. +
+
+
+ +
+ Add models to the queue to generate deployment commands +
+ +
+ +
+
+
+
+ +
+ Commands copied to clipboard! +
+ + + + + + + \ No newline at end of file diff --git a/tests/generate_model_config.py b/tests/generate_model_config.py new file mode 100644 index 00000000..af4d29a3 --- /dev/null +++ b/tests/generate_model_config.py @@ -0,0 +1,354 @@ +#!/usr/bin/env python3 +""" +EMD Model Configuration Generator +Extracts model definitions from Python source and generates JavaScript config file +""" + +import json +import sys +import os +from datetime import datetime +from pathlib import Path + +# Add EMD source to path +current_dir = Path(__file__).parent +project_root = current_dir.parent +sys.path.insert(0, str(project_root / 'src')) + +def extract_models(): + """Extract all registered models with their configurations""" + try: + from emd.models import Model + + models = {} + for model_id, model in Model.model_map.items(): + try: + # Extract model series information + model_series = None + if hasattr(model, 'model_series') and model.model_series: + model_series = { + "name": getattr(model.model_series.model_series_name, 'value', str(model.model_series.model_series_name)) if hasattr(model.model_series, 'model_series_name') else '', + "description": getattr(model.model_series, 'description', ''), + "reference_link": getattr(model.model_series, 'reference_link', '') + } + + models[model_id] = { + "model_id": model.model_id, + "model_type": getattr(model.model_type, 'value', str(model.model_type)) if hasattr(model, 'model_type') else 'unknown', + "description": getattr(model, 'description', ''), + "application_scenario": getattr(model, 'application_scenario', ''), + "supported_instances": [ + getattr(inst.instance_type, 'value', str(inst.instance_type)) if hasattr(inst, 'instance_type') else str(inst) + for inst in getattr(model, 'supported_instances', []) + ], + "supported_engines": [ + getattr(eng.engine_type, 'value', str(eng.engine_type)) if hasattr(eng, 'engine_type') else str(eng) + for eng in getattr(model, 'supported_engines', []) + ], + "supported_services": [ + getattr(svc.service_type, 'value', str(svc.service_type)) if hasattr(svc, 'service_type') else str(svc) + for svc in getattr(model, 'supported_services', []) + ], + "allow_china_region": getattr(model, 'allow_china_region', False), + "huggingface_model_id": getattr(model, 'huggingface_model_id', ''), + "modelscope_model_id": getattr(model, 'modelscope_model_id', ''), + "model_series": model_series + } + except Exception as e: + print(f"āš ļø Warning: Error extracting model {model_id}: {e}") + continue + + return models + except Exception as e: + print(f"āŒ Error importing models: {e}") + return {} + +def extract_instances(): + """Extract all instance definitions""" + try: + from emd.models.instances import Instance + + instances = {} + for instance_type, instance in Instance.instance_map.items(): + try: + instances[getattr(instance_type, 'value', str(instance_type))] = { + "instance_type": getattr(instance_type, 'value', str(instance_type)), + "gpu_num": getattr(instance, 'gpu_num', None), + "neuron_core_num": getattr(instance, 'neuron_core_num', None), + "vcpu": getattr(instance, 'vcpu', 0), + "memory": getattr(instance, 'memory', 0), + "description": getattr(instance, 'description', ''), + "support_cn_region": getattr(instance, 'support_cn_region', False) + } + except Exception as e: + print(f"āš ļø Warning: Error extracting instance {instance_type}: {e}") + continue + + return instances + except Exception as e: + print(f"āŒ Error importing instances: {e}") + return {} + +def extract_engines(): + """Extract engine definitions and descriptions""" + engines = { + "vllm": { + "engine_type": "vllm", + "description": "vLLM - High-performance inference engine optimized for large language models", + "support_inf2_instance": False + }, + "huggingface": { + "engine_type": "huggingface", + "description": "Hugging Face Transformers - Popular library for transformer models", + "support_inf2_instance": False + }, + "tgi": { + "engine_type": "tgi", + "description": "Text Generation Inference - Optimized inference server for text generation", + "support_inf2_instance": True + }, + "ollama": { + "engine_type": "ollama", + "description": "Ollama - Lightweight, high-performance model server", + "support_inf2_instance": False + }, + "llama.cpp": { + "engine_type": "llama.cpp", + "description": "llama.cpp - Efficient C++ implementation for LLaMA models", + "support_inf2_instance": False + }, + "lmdeploy": { + "engine_type": "lmdeploy", + "description": "LMDeploy - High-performance inference engine", + "support_inf2_instance": False + }, + "comfyui": { + "engine_type": "comfyui", + "description": "ComfyUI - Node-based interface for stable diffusion workflows", + "support_inf2_instance": False + }, + "ktransformers": { + "engine_type": "ktransformers", + "description": "KTransformers - Optimized transformer inference engine", + "support_inf2_instance": False + } + } + return engines + +def extract_services(): + """Extract service definitions""" + try: + from emd.models.services import Service + + services = {} + for service_type, service in Service.service_type_maps.items(): + try: + services[getattr(service_type, 'value', str(service_type))] = { + "service_type": getattr(service_type, 'value', str(service_type)), + "name": getattr(service, 'name', ''), + "description": getattr(service, 'description', ''), + "support_cn_region": getattr(service, 'support_cn_region', False), + "need_vpc": getattr(service, 'need_vpc', False) + } + except Exception as e: + print(f"āš ļø Warning: Error extracting service {service_type}: {e}") + continue + + return services + except Exception as e: + print(f"āŒ Error importing services: {e}") + return {} + +def generate_javascript_config(): + """Generate JavaScript configuration file""" + try: + print("šŸ”„ Extracting EMD model configurations...") + + config = { + "metadata": { + "generated_at": datetime.now().isoformat(), + "version": "1.0.0", + "source": "EMD Python Model Definitions" + }, + "models": extract_models(), + "instances": extract_instances(), + "engines": extract_engines(), + "services": extract_services() + } + + # Generate JavaScript file content + js_content = f"""// EMD Model Configuration +// Auto-generated from Python model definitions +// Generated at: {config['metadata']['generated_at']} + +window.EMD_MODEL_CONFIG = {json.dumps(config, indent=2, ensure_ascii=False)}; + +// Helper functions for accessing configuration +window.EMD_HELPERS = {{ + getModel: function(modelId) {{ + return window.EMD_MODEL_CONFIG.models[modelId]; + }}, + + getAllModels: function() {{ + return window.EMD_MODEL_CONFIG.models; + }}, + + getModelsByType: function(type) {{ + const models = {{}}; + for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ + if (model.model_type === type) {{ + models[id] = model; + }} + }} + return models; + }}, + + getInstance: function(instanceType) {{ + return window.EMD_MODEL_CONFIG.instances[instanceType]; + }}, + + getEngine: function(engineType) {{ + return window.EMD_MODEL_CONFIG.engines[engineType]; + }}, + + getService: function(serviceType) {{ + return window.EMD_MODEL_CONFIG.services[serviceType]; + }}, + + getCompatibleInstances: function(modelId) {{ + const model = this.getModel(modelId); + return model ? model.supported_instances : []; + }}, + + getCompatibleEngines: function(modelId) {{ + const model = this.getModel(modelId); + return model ? model.supported_engines : []; + }}, + + getCompatibleServices: function(modelId) {{ + const model = this.getModel(modelId); + return model ? model.supported_services : []; + }}, + + getModelCount: function() {{ + return Object.keys(window.EMD_MODEL_CONFIG.models).length; + }}, + + getGeneratedAt: function() {{ + return window.EMD_MODEL_CONFIG.metadata.generated_at; + }}, + + // Additional utility functions + getModelsByEngine: function(engineType) {{ + const models = {{}}; + for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ + if (model.supported_engines.includes(engineType)) {{ + models[id] = model; + }} + }} + return models; + }}, + + getModelsByInstance: function(instanceType) {{ + const models = {{}}; + for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ + if (model.supported_instances.includes(instanceType)) {{ + models[id] = model; + }} + }} + return models; + }}, + + getModelsByService: function(serviceType) {{ + const models = {{}}; + for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ + if (model.supported_services.includes(serviceType)) {{ + models[id] = model; + }} + }} + return models; + }}, + + getChinaRegionModels: function() {{ + const models = {{}}; + for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ + if (model.allow_china_region) {{ + models[id] = model; + }} + }} + return models; + }}, + + getInstanceSpecs: function(instanceType) {{ + const instance = this.getInstance(instanceType); + if (!instance) return null; + + const specs = []; + if (instance.gpu_num) specs.push(`${{instance.gpu_num}} GPU`); + if (instance.neuron_core_num) specs.push(`${{instance.neuron_core_num}} Neuron`); + specs.push(`${{instance.vcpu}} vCPU`); + specs.push(`${{instance.memory}} GiB`); + + return {{ + text: specs.join(', '), + gpu_num: instance.gpu_num, + neuron_core_num: instance.neuron_core_num, + vcpu: instance.vcpu, + memory: instance.memory + }}; + }} +}}; + +console.log(`āœ… EMD Model Configuration loaded: ${{window.EMD_HELPERS.getModelCount()}} models available`); +console.log(`šŸ“Š Model types: LLM (${{Object.keys(window.EMD_HELPERS.getModelsByType('llm')).length}}), VLM (${{Object.keys(window.EMD_HELPERS.getModelsByType('vlm')).length}}), Embedding (${{Object.keys(window.EMD_HELPERS.getModelsByType('embedding')).length}}), Whisper (${{Object.keys(window.EMD_HELPERS.getModelsByType('whisper')).length}})`); +""" + + # Write JavaScript file + output_file = project_root / "docs" / "model_config.js" + output_file.parent.mkdir(exist_ok=True) + + with open(output_file, "w", encoding="utf-8") as f: + f.write(js_content) + + print(f"āœ… Successfully extracted {len(config['models'])} models") + print(f"āœ… Successfully extracted {len(config['instances'])} instances") + print(f"āœ… Successfully extracted {len(config['engines'])} engines") + print(f"āœ… Successfully extracted {len(config['services'])} services") + print(f"āœ… JavaScript configuration saved to {output_file}") + + # Print some sample data for verification + if config['models']: + print("\nšŸ“‹ Sample models extracted:") + for i, (model_id, model) in enumerate(list(config['models'].items())[:5]): + print(f" {i+1}. {model_id} ({model['model_type']}) - {len(model['supported_instances'])} instances") + + if config['instances']: + print(f"\nšŸ–„ļø Instance types: {', '.join(list(config['instances'].keys())[:10])}{'...' if len(config['instances']) > 10 else ''}") + + return True + + except Exception as e: + print(f"āŒ Error generating model configuration: {e}") + import traceback + traceback.print_exc() + return False + +def main(): + """Main function""" + print("šŸš€ EMD Model Configuration Generator") + print("=" * 50) + + success = generate_javascript_config() + + if success: + print("\nšŸŽ‰ Configuration generation completed successfully!") + print("šŸ“ Output file: docs/model_config.js") + print("šŸ”— Ready for integration with HTML interface") + else: + print("\nšŸ’„ Configuration generation failed!") + + return success + +if __name__ == "__main__": + success = main() + sys.exit(0 if success else 1) \ No newline at end of file From c4d8dee78280994b5164e2c6cde02de6614e3af0 Mon Sep 17 00:00:00 2001 From: Yi Yan Date: Fri, 1 Aug 2025 20:54:08 +0800 Subject: [PATCH 2/5] fix: cleanup --- .github/workflows/generate-model-config.yml | 34 ++--- docs/en/model-generator.html | 150 ++++++++++---------- tests/generate_model_config.py | 78 +++++----- 3 files changed, 131 insertions(+), 131 deletions(-) diff --git a/.github/workflows/generate-model-config.yml b/.github/workflows/generate-model-config.yml index f7730e62..ec98e738 100644 --- a/.github/workflows/generate-model-config.yml +++ b/.github/workflows/generate-model-config.yml @@ -16,18 +16,18 @@ on: jobs: generate-config: runs-on: ubuntu-latest - + steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - + - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.9' - + - name: Cache pip dependencies uses: actions/cache@v3 with: @@ -35,7 +35,7 @@ jobs: key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt', '**/pyproject.toml') }} restore-keys: | ${{ runner.os }}-pip- - + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -47,18 +47,18 @@ jobs: fi # Install additional dependencies that might be needed pip install pathlib datetime - + - name: Create docs directory run: | mkdir -p docs - + - name: Run model configuration generator run: | cd ${{ github.workspace }} python tests/generate_model_config.py env: PYTHONPATH: ${{ github.workspace }}/src - + - name: Check if model config was generated run: | if [ -f docs/model_config.js ]; then @@ -72,52 +72,52 @@ jobs: echo "āŒ Model configuration file was not generated" exit 1 fi - + - name: Commit and push changes if: github.event_name != 'pull_request' run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - + if [ -n "$(git status --porcelain docs/model_config.js)" ]; then git add docs/model_config.js git commit -m "šŸ¤– Auto-update model configuration - + - Generated from EMD Python model definitions - Updated at: $(date -u '+%Y-%m-%d %H:%M:%S UTC') - Triggered by: ${{ github.event_name }} - Commit: ${{ github.sha }}" - + git push echo "āœ… Model configuration updated and committed" else echo "ā„¹ļø No changes to model configuration" fi - + - name: Upload model config as artifact uses: actions/upload-artifact@v3 with: name: model-config path: docs/model_config.js retention-days: 30 - + - name: Generate summary run: | echo "## šŸ“Š Model Configuration Generation Summary" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - + if [ -f docs/model_config.js ]; then echo "āœ… **Status**: Successfully generated" >> $GITHUB_STEP_SUMMARY echo "šŸ“ **Output**: \`docs/model_config.js\`" >> $GITHUB_STEP_SUMMARY echo "šŸ“ **Size**: $(wc -c < docs/model_config.js) bytes" >> $GITHUB_STEP_SUMMARY echo "šŸ“„ **Lines**: $(wc -l < docs/model_config.js)" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - + # Extract model count from the generated file if possible if grep -q "getModelCount" docs/model_config.js; then echo "šŸŽÆ **Generated**: Model configuration with helper functions" >> $GITHUB_STEP_SUMMARY fi - + echo "" >> $GITHUB_STEP_SUMMARY echo "### šŸ“‹ Generated Configuration Includes:" >> $GITHUB_STEP_SUMMARY echo "- šŸ¤– Model definitions and metadata" >> $GITHUB_STEP_SUMMARY @@ -128,4 +128,4 @@ jobs: else echo "āŒ **Status**: Generation failed" >> $GITHUB_STEP_SUMMARY echo "Please check the workflow logs for details." >> $GITHUB_STEP_SUMMARY - fi \ No newline at end of file + fi diff --git a/docs/en/model-generator.html b/docs/en/model-generator.html index 2d581aa7..dc1ed6bf 100644 --- a/docs/en/model-generator.html +++ b/docs/en/model-generator.html @@ -488,11 +488,11 @@ flex-direction: column; height: auto; } - + .config-section, .results-section { width: 100%; } - + .models-table-section { height: 50vh; } @@ -502,11 +502,11 @@ .config-grid { grid-template-columns: 1fr; } - + .models-table { font-size: 0.8rem; } - + .models-table th, .models-table td { padding: 8px 4px; } @@ -567,13 +567,13 @@

Model Deploy CommandLine Generator

- +
-
@@ -620,7 +620,7 @@

Model Information

Extra Parameters

- +
@@ -636,7 +636,7 @@

Extra Parame
-
@@ -706,7 +706,7 @@

Extra Parame - + - \ No newline at end of file + diff --git a/tests/generate_model_config.py b/tests/generate_model_config.py index af4d29a3..5118180b 100644 --- a/tests/generate_model_config.py +++ b/tests/generate_model_config.py @@ -19,7 +19,7 @@ def extract_models(): """Extract all registered models with their configurations""" try: from emd.models import Model - + models = {} for model_id, model in Model.model_map.items(): try: @@ -31,7 +31,7 @@ def extract_models(): "description": getattr(model.model_series, 'description', ''), "reference_link": getattr(model.model_series, 'reference_link', '') } - + models[model_id] = { "model_id": model.model_id, "model_type": getattr(model.model_type, 'value', str(model.model_type)) if hasattr(model, 'model_type') else 'unknown', @@ -57,7 +57,7 @@ def extract_models(): except Exception as e: print(f"āš ļø Warning: Error extracting model {model_id}: {e}") continue - + return models except Exception as e: print(f"āŒ Error importing models: {e}") @@ -67,7 +67,7 @@ def extract_instances(): """Extract all instance definitions""" try: from emd.models.instances import Instance - + instances = {} for instance_type, instance in Instance.instance_map.items(): try: @@ -83,7 +83,7 @@ def extract_instances(): except Exception as e: print(f"āš ļø Warning: Error extracting instance {instance_type}: {e}") continue - + return instances except Exception as e: print(f"āŒ Error importing instances: {e}") @@ -98,7 +98,7 @@ def extract_engines(): "support_inf2_instance": False }, "huggingface": { - "engine_type": "huggingface", + "engine_type": "huggingface", "description": "Hugging Face Transformers - Popular library for transformer models", "support_inf2_instance": False }, @@ -139,7 +139,7 @@ def extract_services(): """Extract service definitions""" try: from emd.models.services import Service - + services = {} for service_type, service in Service.service_type_maps.items(): try: @@ -153,7 +153,7 @@ def extract_services(): except Exception as e: print(f"āš ļø Warning: Error extracting service {service_type}: {e}") continue - + return services except Exception as e: print(f"āŒ Error importing services: {e}") @@ -163,7 +163,7 @@ def generate_javascript_config(): """Generate JavaScript configuration file""" try: print("šŸ”„ Extracting EMD model configurations...") - + config = { "metadata": { "generated_at": datetime.now().isoformat(), @@ -171,11 +171,11 @@ def generate_javascript_config(): "source": "EMD Python Model Definitions" }, "models": extract_models(), - "instances": extract_instances(), + "instances": extract_instances(), "engines": extract_engines(), "services": extract_services() } - + # Generate JavaScript file content js_content = f"""// EMD Model Configuration // Auto-generated from Python model definitions @@ -188,11 +188,11 @@ def generate_javascript_config(): getModel: function(modelId) {{ return window.EMD_MODEL_CONFIG.models[modelId]; }}, - + getAllModels: function() {{ return window.EMD_MODEL_CONFIG.models; }}, - + getModelsByType: function(type) {{ const models = {{}}; for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ @@ -202,42 +202,42 @@ def generate_javascript_config(): }} return models; }}, - + getInstance: function(instanceType) {{ return window.EMD_MODEL_CONFIG.instances[instanceType]; }}, - + getEngine: function(engineType) {{ return window.EMD_MODEL_CONFIG.engines[engineType]; }}, - + getService: function(serviceType) {{ return window.EMD_MODEL_CONFIG.services[serviceType]; }}, - + getCompatibleInstances: function(modelId) {{ const model = this.getModel(modelId); return model ? model.supported_instances : []; }}, - + getCompatibleEngines: function(modelId) {{ const model = this.getModel(modelId); return model ? model.supported_engines : []; }}, - + getCompatibleServices: function(modelId) {{ const model = this.getModel(modelId); return model ? model.supported_services : []; }}, - + getModelCount: function() {{ return Object.keys(window.EMD_MODEL_CONFIG.models).length; }}, - + getGeneratedAt: function() {{ return window.EMD_MODEL_CONFIG.metadata.generated_at; }}, - + // Additional utility functions getModelsByEngine: function(engineType) {{ const models = {{}}; @@ -248,7 +248,7 @@ def generate_javascript_config(): }} return models; }}, - + getModelsByInstance: function(instanceType) {{ const models = {{}}; for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ @@ -258,7 +258,7 @@ def generate_javascript_config(): }} return models; }}, - + getModelsByService: function(serviceType) {{ const models = {{}}; for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ @@ -268,7 +268,7 @@ def generate_javascript_config(): }} return models; }}, - + getChinaRegionModels: function() {{ const models = {{}}; for (const [id, model] of Object.entries(window.EMD_MODEL_CONFIG.models)) {{ @@ -278,17 +278,17 @@ def generate_javascript_config(): }} return models; }}, - + getInstanceSpecs: function(instanceType) {{ const instance = this.getInstance(instanceType); if (!instance) return null; - + const specs = []; if (instance.gpu_num) specs.push(`${{instance.gpu_num}} GPU`); if (instance.neuron_core_num) specs.push(`${{instance.neuron_core_num}} Neuron`); specs.push(`${{instance.vcpu}} vCPU`); specs.push(`${{instance.memory}} GiB`); - + return {{ text: specs.join(', '), gpu_num: instance.gpu_num, @@ -302,31 +302,31 @@ def generate_javascript_config(): console.log(`āœ… EMD Model Configuration loaded: ${{window.EMD_HELPERS.getModelCount()}} models available`); console.log(`šŸ“Š Model types: LLM (${{Object.keys(window.EMD_HELPERS.getModelsByType('llm')).length}}), VLM (${{Object.keys(window.EMD_HELPERS.getModelsByType('vlm')).length}}), Embedding (${{Object.keys(window.EMD_HELPERS.getModelsByType('embedding')).length}}), Whisper (${{Object.keys(window.EMD_HELPERS.getModelsByType('whisper')).length}})`); """ - + # Write JavaScript file output_file = project_root / "docs" / "model_config.js" output_file.parent.mkdir(exist_ok=True) - + with open(output_file, "w", encoding="utf-8") as f: f.write(js_content) - + print(f"āœ… Successfully extracted {len(config['models'])} models") print(f"āœ… Successfully extracted {len(config['instances'])} instances") print(f"āœ… Successfully extracted {len(config['engines'])} engines") print(f"āœ… Successfully extracted {len(config['services'])} services") print(f"āœ… JavaScript configuration saved to {output_file}") - + # Print some sample data for verification if config['models']: print("\nšŸ“‹ Sample models extracted:") for i, (model_id, model) in enumerate(list(config['models'].items())[:5]): print(f" {i+1}. {model_id} ({model['model_type']}) - {len(model['supported_instances'])} instances") - + if config['instances']: print(f"\nšŸ–„ļø Instance types: {', '.join(list(config['instances'].keys())[:10])}{'...' if len(config['instances']) > 10 else ''}") - + return True - + except Exception as e: print(f"āŒ Error generating model configuration: {e}") import traceback @@ -337,18 +337,18 @@ def main(): """Main function""" print("šŸš€ EMD Model Configuration Generator") print("=" * 50) - + success = generate_javascript_config() - + if success: print("\nšŸŽ‰ Configuration generation completed successfully!") print("šŸ“ Output file: docs/model_config.js") print("šŸ”— Ready for integration with HTML interface") else: print("\nšŸ’„ Configuration generation failed!") - + return success if __name__ == "__main__": success = main() - sys.exit(0 if success else 1) \ No newline at end of file + sys.exit(0 if success else 1) From 46612b79d46516b3120ab73e45dc3b76e6e62318 Mon Sep 17 00:00:00 2001 From: Yi Yan Date: Fri, 1 Aug 2025 20:58:57 +0800 Subject: [PATCH 3/5] fix: fix workflow --- .github/workflows/generate-model-config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-model-config.yml b/.github/workflows/generate-model-config.yml index ec98e738..2cd10bac 100644 --- a/.github/workflows/generate-model-config.yml +++ b/.github/workflows/generate-model-config.yml @@ -95,7 +95,7 @@ jobs: fi - name: Upload model config as artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: model-config path: docs/model_config.js From 9143b21d911497fb1b267a2653a2b6446c10c4c6 Mon Sep 17 00:00:00 2001 From: Yi Yan Date: Fri, 1 Aug 2025 21:06:10 +0800 Subject: [PATCH 4/5] doc: fixed branch for model configuration file location --- .github/workflows/generate-model-config.yml | 29 +++++++++------------ 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/.github/workflows/generate-model-config.yml b/.github/workflows/generate-model-config.yml index 2cd10bac..c1995f4b 100644 --- a/.github/workflows/generate-model-config.yml +++ b/.github/workflows/generate-model-config.yml @@ -73,26 +73,21 @@ jobs: exit 1 fi - - name: Commit and push changes - if: github.event_name != 'pull_request' - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - - if [ -n "$(git status --porcelain docs/model_config.js)" ]; then - git add docs/model_config.js - git commit -m "šŸ¤– Auto-update model configuration - + - name: Deploy to GitHub Pages + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs + destination_dir: . + keep_files: true + commit_message: | + šŸ¤– Auto-update model configuration + - Generated from EMD Python model definitions - Updated at: $(date -u '+%Y-%m-%d %H:%M:%S UTC') - Triggered by: ${{ github.event_name }} - - Commit: ${{ github.sha }}" - - git push - echo "āœ… Model configuration updated and committed" - else - echo "ā„¹ļø No changes to model configuration" - fi + - Source commit: ${{ github.sha }} - name: Upload model config as artifact uses: actions/upload-artifact@v4 From 492a026f7be16af64fe6fca30c379e5b9bf3e929 Mon Sep 17 00:00:00 2001 From: Yi Yan Date: Fri, 1 Aug 2025 21:07:37 +0800 Subject: [PATCH 5/5] doc: code cleanup --- .github/workflows/generate-model-config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-model-config.yml b/.github/workflows/generate-model-config.yml index c1995f4b..c082a0e3 100644 --- a/.github/workflows/generate-model-config.yml +++ b/.github/workflows/generate-model-config.yml @@ -83,7 +83,7 @@ jobs: keep_files: true commit_message: | šŸ¤– Auto-update model configuration - + - Generated from EMD Python model definitions - Updated at: $(date -u '+%Y-%m-%d %H:%M:%S UTC') - Triggered by: ${{ github.event_name }}