Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ you can see the sample [fil read in csv](./samples/charts/sbk-file-read.csv) and

### Setup Instructions

#### Setup with Python virtual environment

```
#create the env
python3 -m venv venv-sbk-charts
Expand All @@ -123,6 +125,31 @@ to deactivate from the venv
deactivate
```

#### Setup with conda

```
# Create a new conda environment with Python 3.14 or higher
conda create -n conda-sbk-charts python=3.14 -y
Comment on lines +131 to +132
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Python 3.14 does not exist yet.

Python 3.14 is not released (current stable versions are 3.12/3.13). This will cause conda environment creation to fail. Consider using Python 3.12 or 3.13.

Proposed fix
-# Create a new conda environment with Python 3.14 or higher
-conda create -n conda-sbk-charts python=3.14 -y
+# Create a new conda environment with Python 3.12 or higher
+conda create -n conda-sbk-charts python=3.12 -y
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Create a new conda environment with Python 3.14 or higher
conda create -n conda-sbk-charts python=3.14 -y
# Create a new conda environment with Python 3.12 or higher
conda create -n conda-sbk-charts python=3.12 -y
🤖 Prompt for AI Agents
In `@README.md` around lines 131 - 132, The README currently pins a non-existent
Python version in the conda create command ("conda create -n conda-sbk-charts
python=3.14 -y"); update that command to use a released interpreter (e.g.,
python=3.12 or python=3.13) so environment creation succeeds, and optionally
note a range like "python>=3.12,<3.14" or "python=3.12" for clarity.


# Activate the environment
conda activate conda-sbk-charts

# Install pip if not already installed
conda install pip -y

# Install the project in editable mode using pip
pip install -e .

# Build the sbk-charts package
python -m build
```

To deactivate

```
conda deactivate
```

## Generative AI-Powered Analysis

SBK Charts includes AI-powered analysis descriptions to provide deeper insights into your storage benchmark results.
Expand Down
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ ordered-set~=4.1.0
jproperties~=2.1.1
pillow~=12.0.0
openpyxl-image-loader~=1.0.5
huggingface_hub~=1.2.3
huggingface_hub~=0.34.0
build~=1.3.0
lmstudio~=1.5.0
openai~=2.14.0
requests~=2.32.5
requests~=2.32.5
torch~=2.9.1
transformers~=4.57.3
Comment on lines +13 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check latest available versions of torch and transformers on PyPI
echo "Checking torch versions:"
curl -s https://pypi.org/pypi/torch/json | jq -r '.releases | keys | .[-15:]' | sort -V

echo -e "\nChecking transformers versions:"
curl -s https://pypi.org/pypi/transformers/json | jq -r '.releases | keys | .[-15:]' | sort -V

Repository: kmgowda/sbk-charts

Length of output: 469


Fix invalid transformers version in requirements.txt.

Line 14 specifies transformers~=4.57.3, but this version does not exist on PyPI. Available versions jump from 4.9.2 to 4.57.4. Update to transformers~=4.57.4 or later.

The torch~=2.9.1 version is valid and exists on PyPI.

🤖 Prompt for AI Agents
In `@requirements.txt` around lines 13 - 14, The requirements.txt entry for
transformers is pinned to a non-existent version "transformers~=4.57.3"; update
that token to a valid release (e.g., change "transformers~=4.57.3" to
"transformers~=4.57.4" or a later valid version) while leaving "torch~=2.9.1"
unchanged so pip can resolve packages correctly.

accelerate>=0.20.0 # Required for model parallelism and memory optimization
Binary file modified samples/charts/.DS_Store
Binary file not shown.
Binary file not shown.
17 changes: 13 additions & 4 deletions src/ai/sbk_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"The summary generated by generative AI models may not be complete and accurate. "
"It's recommended to analyze the graphs along with the generated summary.")

DEFAULT_TIMEOUT_SECONDS = 120

def get_t_num_sheet_name(r_num_name):
"""
Expand Down Expand Up @@ -134,7 +135,7 @@ def __init__(self):
self.file = None
self.ai_instance = None
self.web = None
self.timeout_seconds = 120
self.timeout_seconds = DEFAULT_TIMEOUT_SECONDS
self.no_threads = False

def add_args(self, parser):
Expand Down Expand Up @@ -177,19 +178,27 @@ def parse_args(self, args):

Args:
args (argparse.Namespace): Parsed command-line arguments

Side Effects:
- Sets the output file path
- Configures timeout and threading settings
- Configures timeout (converted to int) and threading settings
- Activates the selected AI backend instance if specified
"""
self.timeout_seconds = int(args.seconds) if hasattr(args, 'seconds') and args.seconds is not None else DEFAULT_TIMEOUT_SECONDS
self.file = args.ofile
self.timeout_seconds = args.seconds
self.no_threads = args.nothreads
if args.ai_class:
self.ai_instance = self.ai_instance_map[args.ai_class.lower()]
self.ai_instance.parse_args(args)

def open(self, args):
if self.ai_instance:
self.ai_instance.open(args)

def close(self, args):
if self.ai_instance:
self.ai_instance.close(args)

def load_workbook(self):
"""
Load the Excel workbook from the specified file path.
Expand Down
187 changes: 187 additions & 0 deletions src/custom_ai/pytorch_llm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<!--
Copyright (c) KMG. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
-->
# PyTorch LLM Implementation for SBK Charts

This document describes the PyTorch LLM implementation for SBK Charts, which enables local AI-powered analysis of storage benchmark results using PyTorch and Hugging Face models.

## Overview

The PyTorch LLM implementation allows SBK Charts to leverage local language models through PyTorch's inference capabilities.
This implementation is particularly useful for users who want to run AI analysis locally without relying on external APIs.
This implementation is based on the Hugging Face Transformers library and PyTorch.
you can train the model by providing '--pt-train' option, but the default model : 'openai/gpt-oss-20b' consumes more than 200GB RAM.

## Implementation Details

The PyTorch LLM implementation is located in the `src/custom_ai/pytorch_llm` directory and extends the base AI interface defined in `src/genai/genai.py`.

### Key Features

1. **Local Model Inference**: Runs entirely on your hardware using PyTorch
2. **Hugging Face Integration**: Supports any Causal Language Model from the Hugging Face Hub
3. **Hardware Acceleration**: Automatically utilizes CUDA, MPS, or CPU based on availability
4. **Memory Efficient**: Uses 16-bit or 32-bit precision based on hardware support
5. **Configurable Parameters**: Adjust model parameters like temperature and top-p sampling

## Prerequisites

### Python Dependencies

- PyTorch (with CUDA support recommended for GPU acceleration)
- Transformers library from Hugging Face
- A compatible pre-trained language model (e.g., from Hugging Face Hub)

### Hardware Requirements

- CPU: Modern x86-64 or ARM processor
- RAM: At least 32GB (128GB+ recommended for larger models)
- GPU: NVIDIA GPU with CUDA support recommended for better performance
- Disk Space: 10GB+ for model storage (varies by model size)

## Installation

1. Install PyTorch (with CUDA if available):
```bash
# For CUDA 11.8
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

# For CPU-only
# pip3 install torch torchvision torchaudio
```

2. Install the Transformers library:
```bash
pip install transformers
```

3. (Optional) Install additional dependencies for specific models:
```bash
pip install accelerate bitsandbytes
```

## Configuration

The implementation supports the following configuration options:

- **Model**: Any Hugging Face model ID or local path (default: `openai/gpt-oss-20b`)
- **Device**: Automatically detects CUDA/MPS/CPU (can be overridden)
- **Max Length**: Maximum sequence length for generation (default: 2048)
- **Temperature**: Controls randomness (default: 0.4)
- **Top-p**: Nucleus sampling parameter (default: 0.9)

## Usage

### Basic Usage

```bash
# Process a single CSV file with default settings
sbk-charts -i input.csv -o output.xlsx pytorch_llm

# Process multiple CSV files
sbk-charts -i file1.csv,file2.csv -o output.xlsx pytorch_llm
```

### Advanced Options

```bash
# Specify a different model
sbk-charts -i input.csv -o output.xlsx pytorch_llm --pt-model mistralai/Mistral-7B-v0.1

# Adjust generation parameters
sbk-charts -i input.csv -o output.xlsx pytorch_llm \
--pt-temperature 0.7 \
--pt-top-p 0.95 \
--pt-max-length 1024

# Force CPU usage
sbk-charts -i input.csv -o output.xlsx pytorch_llm --pt-device cpu
```

## Example Commands

```bash
# Process file with default settings
sbk-charts -i ./samples/charts/sbk-file-read.csv -o ./samples/charts/sbk-file-read-pytorch.xlsx pytorch_llm

# Use a smaller model with custom parameters
sbk-charts -i ./samples/charts/sbk-file-read.csv -o ./samples/charts/sbk-file-read-mistral.xlsx pytorch_llm \
--pt-model mistralai/Mistral-7B-v0.1 \
--pt-temperature 0.5 \
--pt-max-length 1024

# Process multiple files
sbk-charts -i ./samples/charts/sbk-file-read.csv,./samples/charts/sbk-rocksdb-read.csv \
-o ./samples/charts/sbk-combined-pytorch.xlsx pytorch_llm
```

## Model Management

### Using Local Models

1. Download a model from Hugging Face Hub:
```bash
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "mistralai/Mistral-7B-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Save locally
save_path = "./saved_models/mistral-7b"
model.save_pretrained(save_path)
tokenizer.save_pretrained(save_path)
```

2. Use the local model:
```bash
sbk-charts -i input.csv -o output.xlsx pytorch_llm --pt-model ./saved_models/mistral-7b
```

## Performance Tips

1. **Use GPU Acceleration**: Ensure CUDA is properly installed for best performance
2. **Quantization**: For large models, consider 4-bit or 8-bit quantization
3. **Batch Processing**: Process multiple files in a single command when possible
4. **Model Size**: Choose an appropriately sized model for your hardware
5. **Execution time**: choose the execution time at least 30 minutes ; you can use the parameter '-secs' parameter

## Troubleshooting

### Common Issues

1. **Out of Memory (OOM) Errors**:
- Reduce `--pt-max-length`
- Use a smaller model
- Enable gradient checkpointing
- Use quantization

2. **Model Loading Issues**:
- Ensure the model name is correct
- Check internet connection if downloading
- Verify disk space is available

3. **CUDA Errors**:
- Check CUDA installation: `nvidia-smi`
- Ensure PyTorch was installed with CUDA support
- Try reducing batch size or model size

## Directory Structure

```
src/
└── custom_ai/
└── pytorch_llm/
├── __init__.py
├── pytorch_llm.py # Main implementation
└── README.md # This document
```
## License

Apache License 2.0
Empty file.
Loading