Input and output processing for IBM Granite models
Project description
Granite IO Processing
Introduction
Granite IO Processing is a framework which enables you to transform how a user calls or infers an IBM Granite model and how the output from the model is returned to the user. In other words, the framework allows you to extend the functionality of calling the model.
Getting Started
Requirements
- Python 3.10+
Installation
We recommend using a Python virtual environment with Python 3.10+. Here is how to setup a virtual environment using Python venv:
python3 -m venv granite_io_venv
source granite_io_venv/bin/activate
[!TIP] If you use pyenv, Conda Miniforge or other such tools for Python version management, create the virtual environment with that tool instead of venv. Otherwise, you may have issues with installed packages not being found as they are linked to your Python version management tool and not
venv.
There are 2 ways to install the Granite IO Processor as follows:
From Release
To install from release (PyPi package):
python3 -m venv granite_io_venv
source granite_io_venv/bin/activate
pip install granite-io
sudo python3 -m nltk.downloader -d /usr/local/share/nltk_data punkt punkt_tab
[!NOTE]
granite-iouses NLTK Data Punkt Sentence Tokenizer for extracting contents when parsing output from a model. The command above shows how to install tokenizers for MacOS. Check out install guide for other OSes.
From Source
To install from source(GitHub Repository):
python3 -m venv granite_io_venv
source granite_io_venv/bin/activate
git clone https://github.com/ibm-granite/granite-io
cd granite-io
pip install -e .
python3 sudo python -m nltk.downloader -d /usr/local/share/nltk_data punkt punkt_tab
[!NOTE]
granite-iouses NLTK Data Punkt Sentence Tokenizer for extracting contents when parsing output from a model. The command above shows how to install tokenizers for MacOS. Check out install guide for other OSes.
Framework Example
Sample code snippet showing how to use the framework:
from granite_io import make_backend, make_io_processor
from granite_io.types import ChatCompletionInputs, UserMessage
model_name = "granite3.2:8b"
io_processor = make_io_processor(
model_name, backend=make_backend("openai", {"model_name": model_name})
)
messages=[
UserMessage(
content="What's the fastest way for a seller to visit all the cities in their region?",
)
]
# Without Thinking
outputs = io_processor.create_chat_completion(ChatCompletionInputs(messages=messages))
print("------ WITHOUT THINKING ------")
print(outputs.results[0].next_message.content)
# With Thinking
outputs = io_processor.create_chat_completion(
ChatCompletionInputs(messages=messages, thinking=True)
)
print("------ WITH THINKING ------")
print(">> Thoughts:")
print(outputs.results[0].next_message.reasoning_content)
print(">> Response:")
print(outputs.results[0].next_message.content)
[!IMPORTANT] To get started with the examples, make sure you have followed the Installation steps first. You will need additional packages to be able to run the OpenAI example. They can be installed by running
pip install -e "granite-io[openai]". Replace package namegranite-iowith.if installing from source.To be able to run the above code snippet, you will need an Ollama server running locally and IBM Granite 3.2 model cached (
ollama pull granite3.2:8b).
Try It Out!
To help you get up and running as quickly as possible with the Granite IO Processing framework, check out the following resources which demonstrate further how to use the framework:
- Python script examples:
[!IMPORTANT] To get started with the examples, make sure you have followed the Installation steps first. You will need additional packages to be able to run the examples. They can be installed by running
pip install -e "granite-io[openai]"andpip install -e "granite-io[litellm]. Replace package namegranite-iowith.if installing from source.You will also need an Ollama server running locally and IBM Granite 3.2 model cached (
ollama pull granite3.2:8b).
- Jupyter notebook tutorials:
[!IMPORTANT] To get started with the examples, make sure you have followed the Installation steps first. You will also need additional packages to be able to run the Jupyter notebook. They can be installed by running
pip install -e "granite-io[transformers]"andpip install -e "granite-io[notebook]". Replace package namegranite-iowith.if installing from source. The notebooks can be then run with following commandjupyter notebook <path_to_notebook>.
Architecture
For more information about architecture and design decisions, refer to docs/design.md.
Contributing
Check out our contributing guide to learn how to contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file granite_io-0.3.0.tar.gz.
File metadata
- Download URL: granite_io-0.3.0.tar.gz
- Upload date:
- Size: 441.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eda48f49386af4e6ccd44b9a8c839aeb702765108f978a391793eb12c18edd4
|
|
| MD5 |
217c46c1726c3860e24c5e56254ef60c
|
|
| BLAKE2b-256 |
3ae224313949137610fccd53d637c9384d275a1f091139f4915e0f79c5618b4a
|
Provenance
The following attestation bundles were made for granite_io-0.3.0.tar.gz:
Publisher:
pypi.yml on ibm-granite/granite-io
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
granite_io-0.3.0.tar.gz -
Subject digest:
7eda48f49386af4e6ccd44b9a8c839aeb702765108f978a391793eb12c18edd4 - Sigstore transparency entry: 194828837
- Sigstore integration time:
-
Permalink:
ibm-granite/granite-io@d59f123077b1a734f93ab88e7f12c515f8a51cae -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ibm-granite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@d59f123077b1a734f93ab88e7f12c515f8a51cae -
Trigger Event:
release
-
Statement type:
File details
Details for the file granite_io-0.3.0-py3-none-any.whl.
File metadata
- Download URL: granite_io-0.3.0-py3-none-any.whl
- Upload date:
- Size: 51.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13303a76136d6c95a5f8a5d9d782700c5e1702a3b0933a3c958f48d90bebfe70
|
|
| MD5 |
c08064dfa8dba6c7b7f3795e47ee9485
|
|
| BLAKE2b-256 |
32c1cd96d0e5c3062a37f1b12f9c165c852c6ab25da626ee09480d15d3af92d2
|
Provenance
The following attestation bundles were made for granite_io-0.3.0-py3-none-any.whl:
Publisher:
pypi.yml on ibm-granite/granite-io
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
granite_io-0.3.0-py3-none-any.whl -
Subject digest:
13303a76136d6c95a5f8a5d9d782700c5e1702a3b0933a3c958f48d90bebfe70 - Sigstore transparency entry: 194828840
- Sigstore integration time:
-
Permalink:
ibm-granite/granite-io@d59f123077b1a734f93ab88e7f12c515f8a51cae -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ibm-granite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@d59f123077b1a734f93ab88e7f12c515f8a51cae -
Trigger Event:
release
-
Statement type: