Python SDK to extract relevant metrics from Small Language Model inference calls.
Project description
cognitor-py
cognitor-py is the Python SDK of our Cognitor platform. It is used to get detailed tracing and observability for Small Language Models applications. All metrics can be saved to a self-hosted instance of the Cognitor platform or to a local file.
At this time, cognitor-py supports HuggingFace transformers models.
Installation
pip install cognitor
Usage
Send logs to a self-hosted instance of Cognitor platform
from cognitor import Cognitor
# Initialize your model and tokenizer
model_name = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
pipe = pipeline("text-generation", model=model_name, tokenizer=tokenizer)
cognitor = Cognitor(
model_name=model_name,
tokenizer=tokenizer,
log_type="database",
host="localhost",
port=5432,
user="postgres",
password="postgres",
dbname="cognitor"
)
# Run inference within the monitor context
with cognitor.monitor() as m:
input_text = "Once upon a time,"
# Use track() to capture only the inference duration
with m.track():
output = pipe(input_text, max_length=50)
m.capture(input_data=input_text, output=output)
Save logs to a local file
from cognitor import Cognitor
# Initialize your model and tokenizer
model_name = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
pipe = pipeline("text-generation", model=model_name, tokenizer=tokenizer)
cognitor = Cognitor(
model_name=model_name,
tokenizer=tokenizer,
log_type="file",
)
# Run inference within the monitor context
with cognitor.monitor() as m:
input_text = "Once upon a time,"
# Use track() to capture only the inference duration
with m.track():
output = pipe(input_text, max_length=50)
m.capture(input_data=input_text, output=output)
Project details
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 cognitor-0.1.0.tar.gz.
File metadata
- Download URL: cognitor-0.1.0.tar.gz
- Upload date:
- Size: 254.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa845eeaed4927fa3cbee7bc5d813c9aac65de497ed71dff4e8549987288edd
|
|
| MD5 |
242d449e130a3f1f8d7354251df3ccce
|
|
| BLAKE2b-256 |
1a77068cc78a67e825076f2cca5c016d321d6aca24f169a8adf7b3471395e398
|
File details
Details for the file cognitor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cognitor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b6f4b4318af73700ddf230f2f8dbc6e1c09d24386af4bd46752969cb759c035
|
|
| MD5 |
81b151aa5451686c05c8b9a73242cd89
|
|
| BLAKE2b-256 |
a2aaf4ffbe8ef73fe26d48609c6a141195a326dcb11db96b0946d09111489736
|