FactoryFactory

Base Models

Base models are the foundation of your fine-tuning workflows in Factory. This guide explains how to select, load, and work with base models efficiently.

Supported Models

Factory supports a variety of open-source models from Hugging Face, including:

  • Qwen Models: Qwen 2.5 series (0.5B, 1.5B, 7B)
  • Llama Models: Llama 3 series (8B, 70B)
  • Phi Models: Microsoft Phi-3 series (Mini, Small)
  • Mistral Models: Mistral series (7B)
  • Gemma Models: Google Gemma series (2B, 7B)

All supported models can be found in the Supported Models documentation.

Loading a Base Model

Factory makes it easy to load models directly from Hugging Face:

from factory_sdk import FactoryClient
 
# Initialize the Factory client
factory = FactoryClient(
    tenant="your_tenant_name",
    project="your_project_name",
    token="your_api_key",
)
 
# Load a model from Hugging Face
model = factory.base_model.with_name("qwen_small") \
    .from_open_weights("Qwen/Qwen2.5-0.5B-Instruct") \
    .save_or_fetch()

This method:

  1. Gives your model a name in Factory ("qwen_small")
  2. Downloads the model from Hugging Face (if not already cached)
  3. Stores a revision in Factory for tracking and reproducibility

How It Works

When you load a base model, Factory:

  1. Checks if the model exists: If you've already downloaded this model, Factory reuses it
  2. Downloads if needed: Downloads model weights from Hugging Face if not available
  3. Creates a fingerprint: Generates a unique identifier for the model version
  4. Stores in Factory: Makes the model available for all your fine-tuning projects

Private Models and Authentication

If you need to load a private model from Hugging Face, you can pass your token:

model = factory.base_model.with_name("my_private_model") \
    .from_open_weights("organization/private-model",
                       huggingface_token="hf_your_token_here") \
    .save_or_fetch()

Model Versioning and Revision Control

Factory automatically tracks all model versions and revisions. When a model is saved, Factory:

  • Stores the model files securely
  • Creates a revision ID for future reference
  • Establishes fingerprints to ensure reproducibility
  • Makes the model available for evaluation, fine-tuning, and deployment

You can view all your models and their revisions in the Factory Hub dashboard.

Best Practices

  • Choose smaller models for faster iteration (0.5B-2B parameters)
  • Use larger models for production-quality results (7B+ parameters)
  • Give descriptive names to your models for easier organization
  • Reuse existing models when possible to save time and storage

Example Workflow

Here's a complete example of loading a base model and preparing for fine-tuning:

from factory_sdk import FactoryClient
 
# Initialize Factory client
factory = FactoryClient(
    tenant="your_tenant_name",
    project="your_project_name",
    token="your_api_key",
)
 
# Load base model
model = factory.base_model.with_name("qwen_small") \
    .from_open_weights("Qwen/Qwen2.5-0.5B-Instruct") \
    .save_or_fetch()
 
# Now you can use this model for fine-tuning or deployment
# For example, create an adapter:
adapter = factory.adapter \
    .with_name("my-adapter") \
    .based_on_recipe(recipe) \
    .using_model(model) \
    .with_hyperparameters(...) \
    .run()

Model Parameters and Types

Supported Model Architectures

Factory currently supports the following model architectures:

SUPPORTED_ARCHITECTURES=[
"Qwen2ForCausalLM",
"LlamaForCausalLM",
"Gemma2ForCausalLM",
"Phi3ForCausalLM",
"Phi3VForCausalLM"
]

When loading a model, Factory automatically verifies that its architecture is supported.

Model Types

Factory works with two main types of model objects:

  1. ModelMeta: The main reference for a model under a specific name. When you refer to a model by name in Factory (e.g., "qwen_small"), you're accessing its ModelMeta.

  2. ModelRevision: A concrete instance of a model with specific weights and parameters.

The key advantage of Factory's approach is that you work with the model name, and Factory automatically manages which revision is used. When you connect a model to your fine-tuning, evaluation, or deployment workflow, Factory tracks the appropriate revision in its dependency graph.

This versioning system provides several benefits:

  • Simplicity: Reference models by name without manually tracking revisions
  • Reproducibility: Factory ensures the correct model version is used throughout your workflow
  • Automatic updates: When you update a model, dependent components can be notified
  • Lineage tracking: Factory maintains the complete history of which model versions were used for which experiments

When you call save_or_fetch(), Factory either creates a new ModelRevision or retrieves an existing one, then connects it properly to your workflow.

Important Parameters

When working with base models, the following parameters are important:

ParameterDescriptionExample
nameYour internal name for the model"qwen_small"
huggingface_nameThe full path on HuggingFace"Qwen/Qwen2.5-0.5B-Instruct"
huggingface_tokenAuthentication token for private models"hf_..."

Model Object Structure

After loading, the model object has the following structure:

ModelObject(
    meta=ModelMeta,  # Metadata about the model
    revision="rev_123456"  # Revision ID
)

You can access this information with:

print(f"Model ID: {model.meta.id}")
print(f"Revision: {model.revision}")

On this page