Instructions to use FardoX/Phi-3-mini-4k-instruct-CAN with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use FardoX/Phi-3-mini-4k-instruct-CAN with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf FardoX/Phi-3-mini-4k-instruct-CAN # Run inference directly in the terminal: llama cli -hf FardoX/Phi-3-mini-4k-instruct-CAN
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf FardoX/Phi-3-mini-4k-instruct-CAN # Run inference directly in the terminal: llama cli -hf FardoX/Phi-3-mini-4k-instruct-CAN
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf FardoX/Phi-3-mini-4k-instruct-CAN # Run inference directly in the terminal: ./build/bin/llama cli -hf FardoX/Phi-3-mini-4k-instruct-CAN
Use Docker
docker model run hf.co/FardoX/Phi-3-mini-4k-instruct-CAN
- Llama new
- LM Studio
- Jan
- vLLM
How to use FardoX/Phi-3-mini-4k-instruct-CAN with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "FardoX/Phi-3-mini-4k-instruct-CAN" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FardoX/Phi-3-mini-4k-instruct-CAN", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/FardoX/Phi-3-mini-4k-instruct-CAN
- Ollama
How to use FardoX/Phi-3-mini-4k-instruct-CAN with Ollama:
ollama run hf.co/FardoX/Phi-3-mini-4k-instruct-CAN
- Unsloth Desktop
- Docker Model Runner
How to use FardoX/Phi-3-mini-4k-instruct-CAN with Docker Model Runner:
docker model run hf.co/FardoX/Phi-3-mini-4k-instruct-CAN
- Lemonade
How to use FardoX/Phi-3-mini-4k-instruct-CAN with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull FardoX/Phi-3-mini-4k-instruct-CAN
Run and chat with the model
lemonade run user.Phi-3-mini-4k-instruct-CAN-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
Phi-3-mini-4k-instruct, CAN 2-bit (research artifact)
Derived work. This repository holds quantized weights of
microsoft/Phi-3-mini-4k-instruct at revision
ff07dc01615f8113924aed013115ab2abd32115b. That is the last revision before the July 2024 weight update; the PV-Tuning paper is from
May 2024. The original model is Β© Microsoft Corporation and released under the MIT License. The license text is in LICENSE and
applies to these derived weights. This is not an official Microsoft release and is not endorsed by Microsoft.
CAN is an additive codebook quantizer:
- Weights are rotated by a block Hadamard transform (blocks of 512) with random signs.
- Each group of 8 weights is the sum of 4 codewords, one from each of 4 codebooks of 16 entries (int8 with an fp32 factor), so 4 nibbles per group.
- One fp16 scale is stored per (row, 512 columns).
- After post-training quantization, a short knowledge distillation (KD) against the FP16 model tunes the scales, codebooks and norms. The codes stay fixed and there is no discrete step.
Files
| file | what | bits/weight, paper count (block linears only) | bits/weight, whole file |
|---|---|---|---|
Phi-3-mini-4k-instruct-CAN128-kd-A.gguf (1.32 GB) |
config A: the 32 blocks' linears in CAN-128; embedding and LM head kept in bf16, as AQLM and PV-Tuning do | 2.031 | 2.753 |
config-B/Phi-3-mini-4k-instruct-CAN-kd-B.gguf (0.97 GB) |
config B: whole model in CAN (LM head CAN-128, embedding CAN-96 = 3 nibbles) | 2.031 | 2.020 |
can3_phi3.patch |
llama.cpp patch adding the CAN128/CAN96 types (CPU only) and enabling the Hadamard fold for phi3 |
sha256:
- A:
ce5f6d4a85f405a58e9d19b239c92ce935a60630a36e175c01188a29e49823b7 - B:
1722f2fba4b1aedb4dd1d8b23a7e2cda7599ab3725b35b2057706b67e3148ffe
Quality: perplexity in the AQLM / PV-Tuning protocol
The protocol follows GPTQ/AQLM:
- context 4096, non-overlapping windows;
- WikiText-2 test, and C4 validation with 256 random windows (seed 0);
- bf16, sdpa attention, default sliding window 2047.
On our harness, FP16 reproduces the published FP16 numbers to within 0.05 %. Our model was evaluated in PyTorch with an exact emulation of the quantized weights; the same weights are in the GGUF files.
| model | bits/weight, paper count | bits/weight, whole model | WikiText-2 | C4 | source |
|---|---|---|---|---|---|
| FP16 | 16 | 16 | 5.83 | 9.35 | measured here (published: 5.83 / 9.35) |
| PV-Tuning | ~2.03 | n/a | 6.88 | 10.08 | published (arXiv 2405.14852, Table 2), not reproduced |
| CAN-128 + KD, config A (this repo) | 2.031 | 2.753 | 8.10 | 12.17 | measured here |
| AQLM | ~2.03 | n/a | 8.85 | 12.19 | published (arXiv 2405.14852, Table 2), not reproduced |
| CAN + KD, config B (this repo) | 2.031 | 2.020 | 8.63 | 12.91 | measured here |
| CAN-128 PTQ only, config A | 2.031 | 2.753 | 9.91 | 14.77 | measured here |
| CAN PTQ only, config B | 2.031 | 2.020 | 10.80 | 16.19 | measured here |
Bits per weight, two counts:
- Paper count. Only the linear layers of the 32 blocks, codebooks and scales included. We believe the papers' "~2.03 bits" excludes embedding and head in the same way, but we have not checked their accounting line by line.
- Whole model. Every tensor, f32 norms included, divided by the 3.82 B parameters.
What this shows:
- Config A beats the published AQLM on WikiText-2 (8.10 vs 8.85) and ties it on C4 (12.17 vs 12.19).
- Config A is still clearly behind PV-Tuning (6.88 / 10.08). This is not a state-of-the-art claim.
- Config B quantizes the embedding and head too, and its file is 0.97 GB.
CPU speed (llama.cpp with this patch)
Setup: Kaggle CPU VM (Intel Xeon @ 2.20 GHz, 4 vCPU), llama-bench -ngl 0 -p 512 -n 128 -r 5 -t 4. We ran 3 passes in rotated order on
one VM; the table shows the median pass and, in brackets, the range across passes.
| model | file | prompt pp512 (t/s) | generation tg128 (t/s) |
|---|---|---|---|
| CAN config A | 1.32 GB | 26.9 [26.7 β 27.1] | 15.8 [13.6 β 15.8] |
Q4_0 (--pure, same base, same VM) |
2.15 GB | 13.6 [13.5 β 13.6] | 7.1 [7.1 β 7.1] |
| ratio CAN / Q4_0 | 0.61Γ size | 1.98Γ | 2.2Γ [1.9 β 2.2] |
Config B, measured on another VM of the same type with the same protocol, against Q4_0 on that VM:
| model | file | pp512 (t/s) | tg128 (t/s) |
|---|---|---|---|
| CAN config B | 0.97 GB | 28.2 [27.1 β 28.8] | 18.1 [18.05 β 18.13] |
Q4_0 (--pure, same VM) |
2.15 GB | 16.1 [15.4 β 16.1] | 7.8 [7.76 β 7.79] |
| ratio CAN-B / Q4_0 | 0.45Γ size | 1.75Γ | 2.3Γ |
Measured on another VM of the same type (2 passes): IQ2_XXS (with a short imatrix) ran tg128 at 4.4β4.6 t/s against 7.9 for Q4_0 there, so about 0.57Γ Q4_0.
Short llama.cpp perplexity as an integrity check: WikiText-2 test, llama-perplexity -c 2048 --chunks 8, which is not the paper
protocol.
- Config A: 6.95 Β± 0.18
- Q4_0: 5.43 Β± 0.15
- IQ2_XXS: 10.55 Β± 0.29
- Config B: 7.33 Β± 0.20 (the same Q4_0 gives 5.43 on that VM too)
Honest caveats
- One run. Every number comes from a single run, with no repeated seeds and no confidence interval. Differences under ~1 % PPL should not be read as real.
- Competitor numbers are copied from the papers, not reproduced here. Our FP16 matching the published FP16 within 0.05 % is the only cross-check of the harness.
- Different training data, same domain as the test. About 20 % of the KD tokens were general text: half WikiText-2 train and half C4 train (C4
enandwikitext-2-raw-v1train splits, streamed). The other 80 % was text generated by the FP16 Phi-3. The PTQ calibration also mixed C4/WikiText-2 train, plus text generated by another model.- This is not the test, but it is the same domain. PV-Tuning used RedPajama. It probably favours our WikiText-2 number relative to theirs.
- C4 validation, used for the C4 metric, was not used in training.
- Little tuning data. KD saw ~1.5 M tokens: 250 steps of 6,144 tokens. The paper fine-tunes on far more.
- Frozen embedding and head in config A. They stay bf16 and are not trained. PV-Tuning also fine-tunes the embedding.
- Different software from 2024. transformers 4.57.6, torch 2.4.1, bf16, sdpa.
- Rebuilt config A file. The original was lost when the GPU pod shut down. We rebuilt it on CPU from the saved KD parameters (codes, scales, codebooks, norms). The rebuild matches the original's tensor count (128 CAN tensors, 65 norms) and bits per weight (2.7530). The llama.cpp perplexity above is a sanity check on the rebuild.
- Speed protocol deviation. The pre-registered speed protocol asked for the median of 3 VMs. We measured 3 passes on 1 VM.
How to run (CPU only)
The files use two new GGML types, CAN128 = 44 and CAN96 = 45. Stock llama.cpp cannot load them. To build a version that can:
curl -L -o llama.tgz https://codeload.github.com/ggml-org/llama.cpp/tar.gz/ad9d9e8f50e6ff9a6bfbbdd3aef6d74a8428cf4e
mkdir llama.cpp && tar xzf llama.tgz -C llama.cpp --strip-components=1 && cd llama.cpp
patch -p1 < /path/to/can3_phi3.patch
cmake -B build -DCMAKE_BUILD_TYPE=Release -DGGML_CUDA=OFF -DGGML_NATIVE=ON -DLLAMA_CURL=OFF
cmake --build build -j --target llama-cli llama-server llama-bench llama-perplexity
./build/bin/llama-cli -m Phi-3-mini-4k-instruct-CAN128-kd-A.gguf -ngl 0 -cnv
- The patch sha256 is
72530b4757b6451f09103b91d89837b449cec5ad23852eefd7682fbe069e824a. - Only the CPU kernels exist (AVX2 path); there is no CUDA or Metal support. Use
-ngl 0. - The GGUF metadata (
prism.hadamard.*) carries the Hadamard rotation, and this llama.cpp commit applies it to the activations. The patch's one-linephi3change allows that for this architecture; llama.cpp's graph coverage check still verifies that every folded weight gets the transform.
- Downloads last month
- 115
We're not able to determine the quantization variants.
Model tree for FardoX/Phi-3-mini-4k-instruct-CAN
Base model
microsoft/Phi-3-mini-4k-instruct