REAL PYTORCH · CPU TRAINING AND AUTOGRAD
Project: Compare full tuning and LoRA budgets
Compare identical splits and step budgets; measure trainable tensors, AdamW state and export bytes.
Run this Lab in Pythilo
Open Labs, choose its topic and tap Download entire topic, or Download entire category for all its Labs, including the required Python packages, then load the starter or worked answer and tap Trace. Progress, pause, resume and removal are in Downloads. Independent checks execute real CPU training and gradients.
That explicit download includes the shared UCI sentiment dataset/tokenizer and 17.7 MB pretrained BERT weights. Its source stays local. After setup it trains and evaluates offline; no API key is needed.
PyTorch is unavailable in this browser runtime. The code and lessons are readable here; execution and checks run in the app.
Pythilo on the App Store →Read lesson: Project: Compare full tuning and LoRA budgets →
Your task
Compare identical splits and step budgets; measure trainable tensors, AdamW state and export bytes. Implement run_project(output, quick=False). Follow the reference report/artifact schema; the checks run quick=True with actual pretrained weights and real data. The full dataset is the default.
Starter
from pathlib import Path
import torch
import pythilo_finetune as ft
def run_project(output, quick=False):
raise NotImplementedError("Implement the training, evidence and artifact contract in the task")Inspect the worked answer
"""Same data, initial classifier, batch order, sequence length and optimizer-step budget."""
from pathlib import Path
import pythilo_finetune as ft
from finetune_projects.full import run_project as full_training
from finetune_projects.lora import run_project as lora_training
def run_project(output, quick=False):
output = Path(output)
full = full_training(output / 'full', quick)
lora = lora_training(output / 'lora', quick)
if full['split_ids'] != lora['split_ids'] or full['steps'] != lora['steps']:
raise ValueError('Unfair comparison: data or optimizer-step budget differs')
# Learning rates differ by method and are declared, not selected on the test.
report = dict(full=full, lora=lora, full_learning_rate=2e-4, lora_learning_rate=1e-3,
trainable_ratio=lora['trainable_parameters'] / full['trainable_parameters'],
optimizer_ratio=lora['optimizer_state_bytes'] / full['optimizer_state_bytes'],
artifact_ratio=lora['artifact_bytes'] / full['artifact_bytes'],
same_step_budget=True, quick=quick,
interpretation='Parameter and optimizer tensor bytes are measured. They are not a peak-RAM measurement. Test scores are descriptive; neither method is guaranteed to win.')
ft.save_json(output / 'comparison.json', report)
return report