Building LLMs on Open-Source Foundations: Cost Calculations and Licensing Essentials
Building large language models on open-source foundations is a popular choice for budget-conscious organizations. This article breaks down the cost structure of pre-training from scratch, examines the lower barrier to entry offered by post-training techniques like SFT and LoRA, and provides a critical checklist for verifying open-source license obligations. Learn how to estimate costs accurately, execute post-training code, and navigate compliance requirements for deploying open-source models.
Building large language models (LLMs) on open-source foundations is a common choice for organizations with limited budgets. To determine if this path is suitable, an organization must calculate the cost of training from scratch, evaluate the barrier to post-training, and verify the obligations under open-source licenses. This article explores these three steps in detail.
1. Cost Structure of Pre-Training from Scratch
Publicly available data provides a reference anchor. The DeepSeek-V3 technical report disclosed that its pre-training phase used approximately 2.788 million H800 GPU hours. Estimated at $2 per GPU hour, this amounts to roughly $5.576 million. However, this figure has a narrow scope: it only accounts for the compute leasing cost of a single successful training run, excluding R&D personnel salaries, data cleaning, architecture exploration, and the compute costs of failed experiments. The numbers will differ significantly when applying other hardware types or considering different organizations.
1. One-Time Investment in Self-Built Hardware
If an organization procures 500 accelerator cards priced at roughly $30,000 per unit, the GPUs alone will cost approximately $15 million. This does not include servers, high-speed networking, data center cooling, and long-term electricity expenses. This is an illustrative estimate; actual prices depend on supply chain cycles, bulk discounts, and exchange rates, and should be based on procurement contracts.
2. Verify the Source of Training Cost Growth Rates
Some opinions suggest that the training cost of frontier models increases 2 to 3 times annually. Due to the lack of a clear statistical standard from specific research institutions, this article does not adopt this claim directly. What is certain is that the demand for training compute in frontier models has steadily grown over the past few years, and the specific growth rate should be based on verifiable research reports.
3. Cost Estimation Template
A preliminary estimate can use the following formula:
Total Cost ≈ Compute Unit Price × Number of GPUs × Training Hours ÷ Effective Utilization Rate + Data Cost + Labor Cost + O&M Cost + Failed Experiment Budget
The effective utilization rate is typically lower than the ideal value, meaning actual compute time often exceeds theoretical estimates. The more experiments conducted, the higher the proportion of the budget that must be reserved for failed experiments.
2. Why the Barrier to Post-Training is Lower
Pre-training establishes foundational language and world knowledge in a model. Post-training adapts the model to specific language styles, industry knowledge, or safety protocols using techniques such as Supervised Fine-Tuning (SFT), Reinforcement Learning from Human Feedback (RLHF), Direct Preference Optimization (DPO), and Low-Rank Adaptation (LoRA). By loading open-source foundation weights, developers can skip the pre-training phase and train directly with domain-specific data.
The table below compares three common methods:
| Method | Data Requirement | Compute Requirement | Main Benefits | Main Risks |
|---|---|---|---|---|
| Full SFT | Typically requires many high-quality samples | High; requires multiple GPUs and ample VRAM | Strong adaptation capability | Prone to overfitting; may weaken general capabilities |
| LoRA / QLoRA | Small to medium scale | Lower; can be attempted on a single GPU | Low cost, fast iteration | Performance ceiling constrained by base model |
| RLHF / DPO | Requires paired preference data | Medium to high | Improves response preference and safety | High annotation cost; reward model may be exploited |
Below is a code skeleton for post-training that can serve as a starting point:
# Example dependencies: transformers>=4.40, datasets, accelerate, torch>=2.1import torchfrom datasets import load_datasetfrom transformers import (AutoModelForCausalLM,AutoTokenizer,DataCollatorForLanguageModeling,Trainer,TrainingArguments,)model_name = "/path/to/local/open_source_model"tokenizer = AutoTokenizer.from_pretrained(model_name)if tokenizer.pad_token is None:tokenizer.pad_token = tokenizer.eos_tokenmodel = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)# Each line in the data file is a JSON object containing a "text" fieldraw = load_dataset("json", data_files="domain_specific_data.json", split="train")def tokenize(batch):return tokenizer(batch["text"], truncation=True, max_length=1024)dataset = raw.map(tokenize, batched=True, remove_columns=raw.column_names)collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)args = TrainingArguments(output_dir="./results",num_train_epochs=3,per_device_train_batch_size=4,gradient_accumulation_steps=8,learning_rate=2e-5,bf16=True,logging_steps=20,save_steps=500,)trainer = Trainer(model=model,args=args,train_dataset=dataset,data_collator=collator,)trainer.train()
Confirm a few things before running. First, dependency versions must match the model’s requirements. Second, bf16 requires a GPU that supports this format. Third, if VRAM is insufficient, consider switching to LoRA or enabling gradient checkpointing to reduce memory usage. Training time depends on parameter size, sample volume, and hardware: a small model might complete in a few hours on a single multi-GPU server, while larger models may take days. After training, evaluate performance on an independent evaluation set rather than relying solely on training loss.
Open-source foundation models generally perform well on public benchmarks for code generation, reasoning, and multilingual tasks. However, there is a gap between public benchmark scores and actual business performance. Teams must evaluate models using their proprietary business data.
3. Open-Source Licensing: Reduced Dependency, Not Zero Obligation
Licenses for open-source models vary significantly. Some adopt MIT or Apache 2.0, permitting commercial use and redistribution. Others, like the terms associated with Llama and Gemma, include usage policies, monthly active user (MAU) clauses, or other commercial restrictions that require individual verification.
The primary benefits of adopting an open-source foundation include:
- Weights can be downloaded and deployed on private servers or cloud instances, eliminating token-based API fees.
- Reduced dependency on SaaS providers for pricing adjustments and service interruptions.
- Data remains within internal environments, helping to meet compliance requirements in industries like finance and government.
- If the license permits modifications, teams can perform secondary training on the foundation model.
However, self-hosting is not without risks. Teams must bear the responsibility for operations, security hardening, model updates, GPU scheduling, and compute cost fluctuations.
Open-Source License Checklist
| Checklist Item | Questions to Confirm |
|---|---|
| Commercial Use | Is commercial use permitted? |
| Distribution | Is closed-source distribution of modified versions allowed? Are copyright notices required? |
| Usage Policy | Are specific scenarios restricted, such as medical, legal, or weaponry? |
| Scale Thresholds | Are there MAU or revenue thresholds? |
| Derivative Naming | Must derivative models use a designated name or provide attribution? |
| Patents & Trademarks | Are patent licenses granted? Is the use of brand names restricted? |
| Data Compliance | Is the training data source traceable? Does it involve personal information? |
| Output Liability | How is liability for generated content allocated? |
This checklist should be verified against the original license text. This article does not constitute legal advice; critical projects should be confirmed by legal professionals.
4. Implementation Recommendations and Risks
When budgets are limited, private deployment is required, and reusable domain-specific data is available, post-training on an open-source foundation is usually a practical choice. If a task requires frontier reasoning capabilities, there is very little data available for training, or the team lacks GPU operations experience, directly calling a mature API or building a small-scale prototype first may be more appropriate.
For infrastructure, use object storage to manage training data and checkpoints, leverage container platforms to schedule distributed training jobs, and deploy logging and monitoring systems to track GPU utilization, memory usage, loss curves, and throughput. This combination helps reduce resource waste, but requires investment to set up and maintain. Smaller teams might first use managed services to validate a solution before deciding to build their own infrastructure.
