quantize: Handle user-defined pruning of whole layers (blocks) #13037
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the ability to prune all tensors from user-defined layers (blocks) by providing a comma-separated list in the
--prune-layers
command line option. It will renumber remaining layers to avoid gaps in the sequence, update the relevant model metadata and, if an imatrix is available, it will use the correct importance score vector.Pruning is restricted to repeating layers only (i.e. blk.n, blk.n+1, etc.) and will not affect single tensors like output, token_embd, etc.
This option can be used alongside
--tensor-type
to perform tensor/layer-wise quantization on selected tensor types, whilst at the same time pruning others. For example:llama-quantize --tensor-type attn=q6_k --prune-layers 3,7,11 --imatrix imatrix.dat model-f32.gguf model-q4_k_m.gguf q4_k_m
It was inspired partly by ShortGPT: Layers in Large Language Models are More Redundant Than You Expect and partly as the next logical step from #12511. It could be used alongside #12718 to guide the layer selection.
Opening a draft PR for now until split tensor testing is completed, but feedback and suggestions are encouraged in the meantime.