All Toolsโ€บLLM Pruner
๐Ÿ’ฌ LLM OptimizationAugust 6, 2026โœ… Tests passing

LLM Pruner

This tool allows AI developers to prune Large Language Models (LLMs) to reduce their size while maintaining performance. It uses techniques like iterative magnitude pruning to remove unnecessary weights, resulting in faster inference times and lower memory usage. This tool is useful for deploying LLMs on devices with limited resources or for reducing the environmental impact of AI models.

Installation

To install the required packages, run:

pip install torch transformers

Usage

To prune an LLM model, run:

python llm_pruner.py --model_path <model_path> --pruning_ratio <pruning_ratio> --output_path <output_path>

Replace <model_path> with the path to the LLM model file, <pruning_ratio> with the desired pruning ratio, and <output_path> with the path to save the pruned model.

Source Code

import argparse
import torch
from transformers import AutoModelForSequenceClassification


def prune_model(model_path, pruning_ratio):
    model = AutoModelForSequenceClassification.from_pretrained(model_path)
    for name, param in model.named_parameters():
        if param.requires_grad:
            param.data = torch.where(torch.abs(param) > pruning_ratio * torch.max(torch.abs(param)), param, torch.zeros_like(param))
    return model


def save_model(model, output_path):
    model.save_pretrained(output_path)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='LLM Pruner')
    parser.add_argument('--model_path', type=str, required=True, help='Path to the LLM model file')
    parser.add_argument('--pruning_ratio', type=float, required=True, help='Pruning ratio')
    parser.add_argument('--output_path', type=str, required=True, help='Path to save the pruned model')
    args = parser.parse_args()
    model = prune_model(args.model_path, args.pruning_ratio)
    save_model(model, args.output_path)

README

LLM Pruner

A tool for pruning Large Language Models (LLMs) to reduce their size while maintaining performance.

Installation

To install the required packages, run:

pip install torch transformers

Usage

To prune an LLM model, run:

python llm_pruner.py --model_path <model_path> --pruning_ratio <pruning_ratio> --output_path <output_path>

Replace <model_path> with the path to the LLM model file, <pruning_ratio> with the desired pruning ratio, and <output_path> with the path to save the pruned model.

Community

Downloads

ยทยทยท

Rate this tool

No ratings yet โ€” be the first!

Details

Tool Name
llm_pruner
Category
LLM Optimization
Generated
August 6, 2026
Tests
Passing โœ…
Fix Loops
3

Quick Install

Clone just this tool:

git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/ptulin/autoaiforge.git
cd autoaiforge
git sparse-checkout set generated_tools/2026-08-06/llm_pruner
cd generated_tools/2026-08-06/llm_pruner
pip install -r requirements.txt 2>/dev/null || true
python llm_pruner.py
LLM Pruner โ€” AI Tools by AutoAIForge