can-i-finetune-this

DaoyuanLi2816MIT活跃维护

单卡微调大模型前的显存预检工具,估算显存占用并给出可直接跑的 LoRA/QLoRA 配置,避免盲目开训就爆显存。

Single-GPU LLM fine-tuning preflight: memory estimates, runnable LoRA/QLoRA recipes, and local measurements.

v0.4.1发布于 2026-10-04 04:31 UTC795star107fork同步于 2026-11-07 23:33 UTC

怎么上手

由 README 提炼,执行前请确认
python -m pip install canifinetune==0.4.1
canifinetune estimate --model Qwen/Qwen2.5-1.5B-Instruct --method qlora --gpu-vram-gb 16 --seq-len 2048 --offline
硬件要求按 README 说明

面向单张消费级 NVIDIA GPU(实测为 RTX 4080);核心估算可纯 CPU 运行,CPU 训练需 fp32。WSL GPU、其他 GPU、Flash Attention 与 Liger 未经验证。

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

单卡微调前的显存预算体检工具,估算内存、给出可跑的 LoRA/QLoRA 配方

单卡微调大模型前的显存预检工具,估算显存占用并给出可直接跑的 LoRA/QLoRA 配置,避免盲目开训就爆显存。

核心能力

  • 按权重、量化、梯度、优化器状态、激活等分项拆解显存占用
  • 核心估算不依赖 PyTorch,也无需下载模型权重
  • 生成可直接运行的 LoRA/QLoRA 训练配方并记录实际配置
  • 本地 demo 在 127.0.0.1:8765 交互式查看拆解并复制命令
  • 实测记录与规划结果分开呈现,标注置信度与安全余量

容易踩的坑

真实训练需另装 canifinetune[train],且限定 Python 3.12 与 Torch 2.6、bitsandbytes 0.49.2 等固定版本;估算结果只是规划参考,README 实测 MAPE 约 46.2%,不保证一定不 OOM;预量化基座、远程模型代码和分布式训练不在支持范围内。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.4.1
  1. v0.4.1v0.4.1 — Visual introduction and bilingual documentation最新正式版2026-10-04 · 2026-10-04 04:31 UTC

    canifinetune

    The project introduction is visual again: the original banner style, a new GPU preflight logo, desktop/mobile architecture diagrams and English/Chinese READMEs connect the first estimate to runnable recipes and local measurements.

    Documentation · 中文入门 · PyPI quickstart

    The new searchable Material site includes workflow, training, architecture, compatibility and evidence guides. It supports mobile layout and dark mode, with English/Chinese search. Core installation remains independent of the documentation stack. PyPI metadata now links to the documentation.

    Install: python -m pip install canifinetune==0.4.1, then try canifinetune demo for the local interactive preflight.

    This presentation patch preserves the 0.4.0 estimator formulas, training behavior and original measurements. Four prior prospective observations remain a small one-GPU/model cohort with 46.2% MAPE and no demonstrated estimator accuracy gain.

    Validation: 102 core tests, generated Python checks, lint/format and mypy; Linux/Windows real CPU integration; strict site build and 809 internal links across 18 HTML pages. The final wheel was built from the sdist and qualified outside the checkout with torch-free core, minimum/recommended CPU full/LoRA, and RTX 4080 CUDA LoRA/QLoRA. Training cases completed two optimizer updates, changed saved tensors, and reloaded for generation; QLoRA exercised actual uint8 optimizer state. These bounded checks establish execution, not language quality or cross-GPU accuracy.

    Release source: ec4465e87ea4e9c9f067c1ff5c37b275999c3667. The attached candidate manifest, qualification receipt and SHA256SUMS identify the exact tested files. Trusted Publishing verifies and uploads those files, then checks the official PyPI distributions and public installation.

  2. v0.4.0canifinetune 0.4.02026-10-04 · 2026-10-04 00:41 UTC
    查看更新说明

    Recipes now preserve native system/multi-turn conversations and use one versioned Transformers runtime with explicit loss masks, truncation and requested/effective configuration. Loader errors cannot silently change precision or attention. Real updates, staged model/adapter saves and reload checks replace template-only validation.

    Start with pip install canifinetune==0.4.0, an offline metadata estimate, or canifinetune demo for the local interactive preflight. Evidence export is opt-in, redacted and manual; community uploads remain unreviewed. GPU discovery records memory sources and uses the lower CUDA-driver/nvidia-smi free reading for an unambiguous single-device budget.

    Compatibility: core Python 3.10–3.14; qualified training Python 3.12/torch 2.6, minimum and recommended constraints. CPU full/LoRA were exercised on Linux and Windows. Local RTX 4080 CUDA LoRA/QLoRA candidate checks execute updates, save and reload outside the checkout. WSL GPU, other GPU hardware, Flash Attention and Liger are not qualified; Liger remains experimental.

    The prospective pinned 0.5B cohort has four three-update successes. Old/new estimates are unchanged and conservatively high (46.2% MAPE); this release does not claim an accuracy improvement or calibrated OOM probability. Historical observations retain their original memory scope and are separate from fits and final candidate qualification.

    Migration: regenerate recipes, install their exact package requirement, remove unknown legacy YAML keys and opt into right truncation deliberately. Default all-token loss is retained. Old calibration caches need regeneration; legacy measurement fits cannot apply to the new estimator. Inference saves do not implement full training resume.

    Select an unquantized base and request quantization explicitly. Pre-quantized checkpoints are rejected before weights: Transformers can retain their own configuration instead of the requested one. Main README links are versioned absolute URLs so they also work on PyPI.

    Quickstart · Training contract · Validation and limits

    Release assets include the exact qualified wheel/sdist, SHA256SUMS, candidate.json and qualification.json. The existing Trusted Publishing workflow verifies these files, uploads them without rebuilding and checks public PyPI hashes and installation. See the attached receipts for commit, software, actual update counts and allocator peaks. Maintainer: Daoyuan Li.

    Post-release verification: the official PyPI wheel and sdist match the qualified hashes exactly. Fresh public-index installations outside the checkout passed torch-free core, CPU full/LoRA and CUDA LoRA/QLoRA updates, saves and reloads. The pinned 0.5B QLoRA quickstart also completed two updates and adapter reload/generation. All three release jobs passed, and PyPI exposes normal publishing attestations. Verification report · Redacted public-install receipt.

  3. v0.3.0v0.3.0 — accurate MoE estimates and safer workflows2026-07-23 · 2026-07-23 05:02 UTC
    查看更新说明

    This release improves estimate accuracy for mixture-of-experts models and tightens the benchmark, calibration, and recipe workflows.

    Highlights:

    • use exact safetensors parameter counts when available
    • account for stored and active experts in MoE models
    • separate quantization metadata from packed weight memory
    • calibrate dynamic memory without rescaling static weights
    • fail clearly when QLoRA or 8-bit optimizer dependencies are unavailable
    • add safer recipe generation and optional Liger kernels
    • expand CI coverage through Python 3.14

    See CHANGELOG.md for the complete list of changes.

  4. v0.2.0v0.2.0 — the estimator now tracks measured VRAM2026-07-02 · 2026-07-02 05:46 UTC
    查看更新说明

    Estimator accuracy overhaul

    The static estimate was 0.5–3.9× off versus real training peaks — worst at long seq_len and for untied-embedding models, and in the dangerous direction (configs called feasible could OOM). 0.2.0 rewrites the memory model against measured torch.cuda traces on an RTX 4080:

    • New logits / loss component — the (batch × seq × vocab) logits + fp32 cross-entropy chain (~14 B per token per vocab entry). For a 152k-vocab model at seq 2048 this is ~4.1 GiB, the single largest training buffer, and gradient checkpointing does not remove it. Previously unmodeled.
    • QLoRA weights are no longer "all params × 0.5 B" — only Linear layers are 4-bit; embeddings, lm_head (twice for untied models), and norms stay full precision and are upcast to fp32 by prepare_model_for_kbit_training. Measured: Qwen2.5-7B loads at 7.2 GiB, not 3.9. tie_word_embeddings is now part of model metadata.
    • Activation coefficients re-fitted for the modern stack (SDPA, SwiGLU-width MLPs, fp32 k-bit intermediates); checkpointing charges saved block inputs plus a single-layer recompute peak; NF4 double-quant absmax overhead corrected to the measured 0.017 B/param.

    Across ten measured configurations (0.5B–7B, seq 512–4096, batch 1–2, checkpointing on/off, LoRA + QLoRA) the estimated real components land within 0.93–1.05× of max_memory_allocated, with the headroom terms keeping the total slightly conservative. Those runs ship as regression fixtures in tests/test_estimator_accuracy.py, and docs/rtx4080_baselines.md shows estimated-vs-measured for every row.

    Expect estimates to be higher than 0.1.x — they were wrong before, not the workload. A 12 GB card asking about 7B QLoRA now correctly hears "no" (11.2 GB measured).

    Fixes

    • Generated train.py recipes no longer train on padding: labels are masked to -100 via attention_mask (a real EOS survives even when pad_token == eos_token).
    • Infeasible full fine-tunes now get "switch to QLoRA" as the first degradation suggestion instead of no-op LoRA-rank reductions.
    • Bench result filenames encode checkpointing / quantization / scope / forward-only, so A/B runs stop overwriting each other.
    • Reports show - instead of a misleading quantization scheme for non-QLoRA rows; calibration skips smoke-scale samples and scales the logits term consistently.

    Data

    The committed benchmark grid grew to 12 configurations (seq 512–4096, batch 1–2, ckpt on/off, LoRA + QLoRA, 0.5B–7B) with fresh estimates embedded, and scripts/run_4080_baselines.sh reproduces the whole table.

  5. v0.1.1canifinetune 0.1.12026-06-10 · 2026-06-10 07:14 UTC
    查看更新说明

    Docs-only patch release — first release published via PyPI trusted publishing.

    • README masthead: SVG hero banner (also rendered on the PyPI project page), centered badges
    • Architecture diagram now uses an absolute URL so it renders on PyPI
    • No code changes since 0.1.0

    Install: pip install canifinetune

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    CI PyPI 0.4.1 Docs Python License: MIT

    Can I fine-tune this LLM on my GPU? Make a plan before loading the weights.

    You have one consumer NVIDIA GPU and an open-weight model in mind. How much memory will training need? Which sequence length, batch size and LoRA rank should you start with? What should you change when the budget is tight?

    canifinetune turns those questions into a memory breakdown, configuration suggestions and a runnable recipe. Then it helps you measure an actual local run and compare the observation with the plan. Core estimation needs no PyTorch and no model-weight download.

    Your first result

    Start in a virtual environment; you do not need to clone this repository.

    python -m pip install canifinetune==0.4.1
    canifinetune estimate --model Qwen/Qwen2.5-1.5B-Instruct --method qlora --gpu-vram-gb 16 --seq-len 2048 --offline
    canifinetune demo
    

    The estimate is 8.420 GiB, YES against a 16 GiB budget, with heuristic confidence medium. It includes the stock logits/loss allocation and a separate safety allowance. A planning result is not a guarantee that training will fit.

    demo serves a local interactive entry at 127.0.0.1:8765. Choose a model, training settings and total/currently-free memory; inspect the breakdown and copy matching CLI commands. It uses the same Python estimator.

    Choose your path

    You want to…Start hereWhat you get
    Check a memory budgetEstimate and recommendA component breakdown, assumptions and candidate configurations
    Run a real fine-tunePyPI-only quickstartA pinned 0.5B QLoRA recipe, real updates, an adapter and a reload check
    Try training without Hub weightsOffline CPU smokeA locally created tiny model and full update/save/reload execution
    Understand or contribute evidenceMeasurements and limitsDefined metrics, raw observations and opt-in redacted export

    How it works

    One configuration contract connects the plan to execution. The estimate accounts for weights, quantization, trainable gradients, optimizer state, activations, logits/loss and overhead. Generated recipes use one Transformers/PEFT runtime, preserve system and multi-turn data, and record requested/effective settings. Benchmarks cover loading, first optimizer-state allocation and the bounded updates.

    • Inspect the budget. See where memory goes, including large-vocabulary loss buffers and the unquantized parts of QLoRA models.
    • Carry the configuration through. Dtype, attention, targets, optimizer, checkpointing, quantization and supervision have explicit meanings and errors.
    • Get usable artifacts. Recipes save a full model or adapter through a staged save, record the outcome and provide a reload/generation command.
    • Keep evidence traceable. Reports separate measured peaks, planning safety, historical fits, independent observations and unreviewed community submissions.

    Architecture guide · Training/data contract

    What has been measured

    On a native Windows RTX 4080, four predeclared Qwen2.5-0.5B-Instruct cases covered LoRA/QLoRA at sequence 256/512, with three updates each. Reserved peaks ranged from 1.666 to 2.398 GiB. Old/new estimator predictions were identical and conservative: 46.2% MAPE, four overestimates, no demonstrated accuracy gain.

    This is a small prospective cohort on one GPU/model, separate from historical measurements used during estimator development. It does not establish a general OOM probability. Candidate/public-package qualification additionally executes CPU full/LoRA and CUDA LoRA/QLoRA updates, saves and reloads. Tiny smoke proves the pipeline, not useful fine-tuned language quality.

    Prospective validation and raw records · Historical baselines

    Install and compatibility

    LayerInstallScope
    Corepip install canifinetune==0.4.1Python 3.10–3.14; estimate, recommend, recipes, reports and local demo
    TrainingQualified Torch wheel, then pip install "canifinetune[train]==0.4.1" with constraintsPython 3.12; real training and benchmarks
    Reporting extraspip install "canifinetune[report]==0.4.1"Optional pandas/tabulate

    Training uses Torch 2.6, minimum/recommended Transformers/PEFT/Accelerate stacks and bitsandbytes 0.49.2. The quickstart separates Windows and Linux/WSL commands. Native Windows CPU/CUDA and Linux CPU are qualified; WSL GPU, other GPUs, Flash Attention and Liger are not qualified. CPU requires fp32; pre-quantized bases, remote model code and distributed training are outside supported execution. Inference artifacts do not include full optimizer/RNG resume state.

    Compatibility and migration · Troubleshooting

    Contribute and develop

    Improve a documented model family, reproduce a bounded measurement, or make the first-use workflow clearer. Measurements are manual and opt-in, redacted by default and unreviewed until checked; uploads do not automatically enter fits.

    python -m pip install -e ".[dev]"
    ruff check .
    ruff format --check .
    mypy src
    pytest -q -m "not training" --cov=canifinetune --cov-fail-under=70
    python scripts/check_generated.py
    

    Contributing · Changelog · Release process · License

    MIT. Maintainer: Daoyuan Li.