User Story
As a developer, I want to easily download and use popular, pre-trained models directly within AiDotNet, so I can quickly build powerful applications with state-of-the-art performance without needing to train models from scratch.
Problem & Proposed Solution
Modern AI development heavily relies on leveraging pre-trained models. Currently, AiDotNet lacks a built-in mechanism for this, forcing users to manually download and convert weights. Hugging Face Hub is the gold standard, but we can do more than just download files.
This plan outlines a Comprehensive Model Hub Ecosystem for AiDotNet. It includes not only a robust client for downloading and caching models (FromPretrainedAsync) but also defines a standard "model package" format and specifies the creation of Python-based conversion tools. These tools are a critical accelerator, enabling the community to port existing PyTorch models to the AiDotNet Hub.
Phase 1: Core Hub Client and Caching System
Goal: Build the foundational client for resolving, downloading, and caching model packages from a central repository.
AC 1.1: Define the "Model Package" Standard (3 points)
Requirement: Specify a clear, structured format for a model on the hub.
AC 1.2: Implement the ModelHub Caching Service (8 points)
Requirement: Create a static class to manage the download and caching of model packages.
Phase 2: The FromPretrained API
Goal: Create a simple, powerful API for users to instantiate AiDotNet models directly from the hub.
AC 2.1: Implement FromPretrainedAsync in a Factory (13 points)
Requirement: Add a static factory method that orchestrates the download and instantiation process.
Phase 3: Ecosystem Expansion - Conversion and Discovery
Goal: Build tools that make the hub useful and empower the community to contribute.
AC 3.1: Create PyTorch-to-AiDotNet Converter Script (13 points)
Requirement: A Python script to convert Hugging Face PyTorch models to the AiDotNet model package format. This is the most critical "expanded feature".
AC 3.2: Implement Hub Search Functionality (5 points)
Requirement: Allow users to discover available models.
Phase 4: Integration and Testing
Goal: Verify the entire ecosystem, from conversion to instantiation.
AC 4.1: End-to-End Integration Test (8 points)
Requirement: A test that verifies the entire workflow: convert a model, host it, and load it with FromPretrainedAsync.
Definition of Done
⚠️ CRITICAL ARCHITECTURAL REQUIREMENTS
Before implementing this user story, you MUST review:
Mandatory Implementation Checklist
1. INumericOperations Usage (CRITICAL)
2. Inheritance Pattern (REQUIRED)
3. PredictionModelBuilder Integration (REQUIRED)
4. Beginner-Friendly Defaults (REQUIRED)
5. Property Initialization (CRITICAL)
6. Class Organization (REQUIRED)
7. Documentation (REQUIRED)
8. Testing (REQUIRED)
⚠️ Failure to follow these requirements will result in repeated implementation mistakes and PR rejections.
See full details: .github/USER_STORY_ARCHITECTURAL_REQUIREMENTS.md
User Story
Problem & Proposed Solution
Modern AI development heavily relies on leveraging pre-trained models. Currently, AiDotNet lacks a built-in mechanism for this, forcing users to manually download and convert weights. Hugging Face Hub is the gold standard, but we can do more than just download files.
This plan outlines a Comprehensive Model Hub Ecosystem for AiDotNet. It includes not only a robust client for downloading and caching models (
FromPretrainedAsync) but also defines a standard "model package" format and specifies the creation of Python-based conversion tools. These tools are a critical accelerator, enabling the community to port existing PyTorch models to the AiDotNet Hub.Phase 1: Core Hub Client and Caching System
Goal: Build the foundational client for resolving, downloading, and caching model packages from a central repository.
AC 1.1: Define the "Model Package" Standard (3 points)
Requirement: Specify a clear, structured format for a model on the hub.
modelId(e.g.,ooples/mamba-2.9b).model_weights.bin: The raw model parameters in a standardized binary format.model_config.json: A JSON file defining the model's architecture, layers, dimensions, and all other parameters needed to construct the model class in AiDotNet.preprocessor_config.json(Optional): Configuration for any required data preprocessing (e.g., image normalization stats, tokenizer vocabulary).README.md: A markdown file with model details, usage examples, and license information.AC 1.2: Implement the
ModelHubCaching Service (8 points)Requirement: Create a static class to manage the download and caching of model packages.
src/AiDotNet.Hub.src/Hub/ModelHub.cs.C:\Users\username\.aidotnet\hub).public static async Task<string> ResolveAsync(string modelId).modelId, checks if the corresponding package is in the cache. If not, it downloads the package from a central repository (e.g., a designated public URL).Phase 2: The
FromPretrainedAPIGoal: Create a simple, powerful API for users to instantiate AiDotNet models directly from the hub.
AC 2.1: Implement
FromPretrainedAsyncin a Factory (13 points)Requirement: Add a static factory method that orchestrates the download and instantiation process.
src/Factories/NeuralNetworkFactory.cs).public static async Task<IModel<T>> FromPretrainedAsync(string modelId).ModelHub.ResolveAsync(modelId)to download/cache the model package and get its local path.model_config.json.architecture_typefield in the config to instantiate the correct AiDotNet model class (e.g.,new Mamba<T>(config)ornew Transformer<T>(config)).model_weights.bininto the newly created model instance.Phase 3: Ecosystem Expansion - Conversion and Discovery
Goal: Build tools that make the hub useful and empower the community to contribute.
AC 3.1: Create PyTorch-to-AiDotNet Converter Script (13 points)
Requirement: A Python script to convert Hugging Face PyTorch models to the AiDotNet model package format. This is the most critical "expanded feature".
tools/converters.convert_hf_to_adn.py) that usestransformersandtorch.model_idas input.state_dictand saves the weights in themodel_weights.binformat (e.g., simple flat binary file).config.json, transforms it, and saves it as ourmodel_config.json.README.md.toolsdirectory explaining how to use the script.AC 3.2: Implement Hub Search Functionality (5 points)
Requirement: Allow users to discover available models.
index.jsonfile. This file will be an array of objects, each containing amodelIdand a shortdescription.public static async Task<IEnumerable<ModelInfo>> SearchAsync(string query)inModelHub.cs.index.json, cache it for a short period, and perform a simple case-insensitive search on themodelIdanddescriptionfields.Phase 4: Integration and Testing
Goal: Verify the entire ecosystem, from conversion to instantiation.
AC 4.1: End-to-End Integration Test (8 points)
Requirement: A test that verifies the entire workflow: convert a model, host it, and load it with
FromPretrainedAsync.convert_hf_to_adn.pyscript to convert a very small, simple Hugging Face model (e.g.,google/bert_uncased_L-2_H-128_A-2).NeuralNetworkFactory.FromPretrainedAsync("test-org/tiny-bert"), pointing the hub client to the local test server.Definition of Done
var model = await NeuralNetworkFactory.FromPretrainedAsync("org/model-name");.Before implementing this user story, you MUST review:
.github/USER_STORY_ARCHITECTURAL_REQUIREMENTS.md.github/PROJECT_RULES.mdMandatory Implementation Checklist
1. INumericOperations Usage (CRITICAL)
protected static readonly INumericOperations<T> NumOps = MathHelper.GetNumericOperations<T>();in base classdouble,float, or specific numeric types - use genericTdefault(T)- useNumOps.ZeroinsteadNumOps.Zero,NumOps.One,NumOps.FromDouble()for valuesNumOps.Add(),NumOps.Multiply(), etc. for arithmeticNumOps.LessThan(),NumOps.GreaterThan(), etc. for comparisons2. Inheritance Pattern (REQUIRED)
I{FeatureName}.csinsrc/Interfaces/(root level, NOT subfolders){FeatureName}Base.csinsrc/{FeatureArea}/inheriting from interface3. PredictionModelBuilder Integration (REQUIRED)
private I{FeatureName}<T>? _{featureName};toPredictionModelBuilder.csBuild()with default:var {featureName} = _{featureName} ?? new Default{FeatureName}<T>();4. Beginner-Friendly Defaults (REQUIRED)
ArgumentExceptionfor invalid values5. Property Initialization (CRITICAL)
default!operator= string.Empty;= new List<T>();or= new Vector<T>(0);NumOps.Zero6. Class Organization (REQUIRED)
src/Interfaces/(root level)src/Regularization/→namespace AiDotNet.Regularization)7. Documentation (REQUIRED)
<b>For Beginners:</b>sections with analogies and examples<param>,<returns>,<exception>tags8. Testing (REQUIRED)
See full details:
.github/USER_STORY_ARCHITECTURAL_REQUIREMENTS.md