An advanced memory calculator for LLMs, helping researchers and practitioners estimate memory requirements for both training and inference.
Compute Gauge is a powerful web-based tool that provides accurate memory calculations for machine learning models. It helps you:
- Calculate memory requirements for model weights
- Estimate KV cache memory usage
- Determine activation memory needs
- Plan training memory requirements
- Support various model architectures
- Recommend GPU configurations
-
Comprehensive Memory Calculation
- Model weights memory
- Key-Value cache memory
- Activation memory
- Optimizer states memory
- Gradient memory
-
Multiple Precision Support
- float32
- float16
- bfloat16
- int8
- int4
-
Training Optimizers
- AdamW
- Quantized AdamW
- SGD
-
Pre-configured Models
- LLama
- Mixtral
- Qwen
- Nvidia Nemotron
- Go 1.21 or later
- Clone the repository
git clone https://github.com/NathanaelTamirat/ComputeGauge.git
cd ComputeGauge
- Install dependencies
go mod download
- Run the application
go run main.go
- Open your browser and navigate to:
http://localhost:8080
- Select a predefined model or enter custom parameters
- Adjust batch size, sequence length, and other parameters
- Choose precision and optimizer (for training)
- Click "Calculate" to see detailed memory breakdowns
Endpoint: POST /api/calculate
Request Body:
{
"model_size": 7,
"precision": "float16",
"batch_size": 1,
"sequence_length": 2048,
"hidden_size": 4096,
"num_hidden_layers": 32,
"num_attention_heads": 32,
"optimizer": "AdamW",
"trainable_params": 100
}
Response:
{
"model_weights": "14.00 GB",
"kv_cache": "1.07 GB",
"activation_memory": "2.34 GB",
"optimizer_memory": "56.00 GB",
"gradients_memory": "28.00 GB",
"total_memory": "101.41 GB"
}
compute-gauge/
├── api/
│ └── v1/
│ └── handler.go # Vercel serverless entry point
├── cmd/
│ └── compute-gauge/
│ └── main.go # Local development entry point
├── internal/ # Private application code
│ ├── app/
│ │ └── server.go
│ ├── config/
│ │ └── models.go
│ ├── handlers/
│ └── models/ # Model JSON definitions
├── pkg/ # Public, reusable packages
│ ├── calc/
│ │ └── utils.go
│ ├── gpu/
│ │ └── recommendations.go
│ └── memory/
│ ├── calculator.go
│ └── types.go
├── web/
│ ├── static/
│ └── templates/
│ └── index.html
└── go.mod
└── go.sum
MIT License
Copyright (c) 2024 Nathanael
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[1] https://huggingface.co/docs/transformers/model_memory_anatomy
[2] https://huggingface.co/docs/transformers/perf_train_gpu_one
[3] https://developer.nvidia.com/blog/mastering-llm-techniques-inference-optimization/
[6] https://www.oreilly.com/library/view/generative-ai-on/9781098159214/ch04.html