Skip to main content

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

cognitor-0.1.1.tar.gz (254.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cognitor-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file cognitor-0.1.1.tar.gz.

File metadata

  • Download URL: cognitor-0.1.1.tar.gz
  • Upload date:
  • Size: 254.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for cognitor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 211d6540ecc00f468befe4d9a5cecb7bd1484027d60d7210440bd752d880152b
MD5 3efdb512e986901b2e8f3035ad5d640f
BLAKE2b-256 fd480020c3c061392ac0ac50355f38e2973143a17a787d4e8b2019d27264f268

See more details on using hashes here.

File details

Details for the file cognitor-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cognitor-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for cognitor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac4f8a1111fd73a9e0237959bcaebd2a8f550b38629c8eab9ebd191c6f045c5c
MD5 5f7be0a8f9f3b2ee7a0afa58fbf948e0
BLAKE2b-256 a849ca00865bde1aa1543c51f380cb391b53d15d9a003e625fd8c0f013ede57a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page