How huggingface/smollm works
Main Components
• Text Processing & Language Models (SmolLM2):
– Contains code and resources under the “text/” directory. This includes pretraining, fine-tuning, data-related scripts, and evaluation pipelines.
– Includes several pretraining routines, continual pretraining scripts (with fine datasets like FineMath and FineWeb-Edu), and scripts for instruction tuning.
• Vision Processing & Vision-Language Models (SmolVLM):
– All vision-related resources are located in the “vision/” directory.
– It includes data processing for images, evaluation experiments, finetuning notebooks (e.g., in the vision/finetuning folder) and evaluation pipelines.
• Tools & Inference Utilities:
– The “tools/” directory contains shared utilities as well as local inference tools for both SmolLM (e.g., “smollm_local_inference”) and SmolVLM (“smolvlm_local_inference”), plus “smol_tools” (for lightweight helper functions).
• Supporting Infrastructure:
– GitHub workflows (CI/CD) under “.github/workflows”.
– Evaluation and experimentation scripts are spread over “vision/experiments”, “text/evaluation”, and modules under “vision/m4” (for additional model variations and experimental evaluation).
– Data sourcing & processing pipelines in “vision/data” and “vision/m4/sourcing”, and supplementary tools in “tools/” and “text/pretraining”.
Relationships and Interactions Between Components
• Data Flow & Pipeline Stages:
– Data ingestion, cleaning, and preprocessing scripts for both language and vision datasets (as seen in the “text/data”, “vision/data”, and “vision/m4/sourcing” directories).
– Training and pretraining pipelines for language and vision models exchange data with pretraining scripts (e.g., “text/pretraining” contains subfolders for continual pretraining and multiple config files).
– Finetuning and evaluation modules take the pretrained models into production settings (e.g., “vision/finetuning” and “text/finetuning”).
• Inference & Tools:
– Tools for local inference serve as additional components that likely interact with the model APIs; they load models and process queries.
• Modular Components:
– Although the models (language and vision) are distinct, they share common patterns in development (using Hugging Face’s Transformers libraries and unified API calls) and possibly leverage common training utilities.
Important Architectural Patterns and Design Principles
• Separation of Concerns:
– The repository is clearly modularized into dedicated directories for text and vision pipelines, adhering to a separation between different modalities.
• Pipeline Patterns:
– Pretraining, fine-tuning, and evaluation pipelines appear to be defined as separate jobs and scripts (using Slurm scripts for distributed training/evaluation).
• Extensibility:
– Numerous configuration and patch files allow for extending the pipelines based on dataset variations (e.g., different YAML configs for SmolLM2 and multiple slurm templates for VLM).
• Utilization of Standard Libraries:
– Use of Hugging Face’s Transformers, along with custom modules (e.g., “smol_tools” and model configuration scripts).
Relevant Technologies and Frameworks
• Core AI/ML Framework: Transformers, PyTorch, Hugging Face libraries.
• Data Processing: Python scripts for dataset cleaning and preparation, including scripts that run as Slurm jobs.
• CI/CD: GitHub workflows for security (trufflehog) and potentially other integration tasks.
• Deployment: Dockerfile in “text/finetuning” and various shell/Slurm scripts for distributed training and evaluation.
Final Advice
Happy diagramming!