Skip to main content

A simplified AI library for model management, inference, and fine-tuning.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Cognix AI Library 🚀

Cognix is a powerful yet simplified Python library for model management, inference, and fine-tuning. It provides a high-level API to interact with Hugging Face models effortlessly, built for developers who want to integrate AI without the boilerplate.

Installation

pip install cognix

Features

  • Simplified Model Loading: Load models for Chat, Vision, or Classification with one line.
  • Robust Error Handling: Improved fallback mechanisms for ImportError and model compatibility.
  • Easy Fine-Tuning: Built-in support for LoRA/QLoRA for efficient training.
  • Hugging Face Integration: Secure login and seamless model downloading.
  • Unified Interface: generate() for LLMs, predict() for Vision/Classification.

Quick Start

1. Login to Hugging Face

import cognix

# Method 1: Explicit token
cognix.login("your_hf_token")

# Method 2: Uses HUGGING_FACE_HUB_TOKEN environment variable
cognix.login()

2. Load and Use an LLM (Chat)

import cognix

try:
    # Load a model for chat (supports 4bit/8bit quantization)
    model = cognix.load_model("gpt2", task="chat")
    
    # Generate text
    response = model.generate("The future of AI is")
    print(f"AI: {response}")
except Exception as e:
    print(f"Error loading model: {e}")

3. Image Classification / Vision (Improved)

Cognix now handles older versions of transformers gracefully.

import cognix

# Load a vision model (e.g., BLIP or ViT)
vision_model = cognix.load_model("Salesforce/blip-image-captioning-base", task="vision")

# Predict from URL, local path, or PIL Image
result = vision_model.predict("https://example.com/image.jpg")
print(f"Description: {result}")

Error Handling & Edge Cases

Cognix is designed to fail gracefully. Here are common scenarios handled:

Scenario Behavior
Missing bitsandbytes Automatically disables 4-bit/8-bit quantization and tries to load in full precision.
Invalid Image URL Returns a clear error message instead of crashing.
Model Incompatibility Falls back to generic AutoModel if specialized classes like AutoModelForVision2Seq fail.
Login Failure Provides detailed feedback if the token is invalid or there's no connection.
Missing PEFT Informs the user that peft is required only when trying to use the Trainer.

Fine-Tuning with LoRA

import cognix

# Load model and dataset
model = cognix.load_model("gpt2", task="chat", quantization="4bit")
dataset = cognix.load_dataset("my_data.json")

# Initialize trainer
trainer = cognix.Trainer(model, dataset, output_dir="./my_fine_tuned_model")

# Train with built-in validation!
if trainer.train(epochs=1, lr=5e-5, batch_size=4):
    trainer.save()
else:
    print("Training failed. Check logs for details.")

License

MIT

Contributing

Visit our GitHub: github.com/golemgamer/cognix

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

cognix_ai-0.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

cognix_ai-0.1.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cognix_ai-0.1.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cognix_ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 33f7e862027ab822ae3c97d74f5da8c33ab9edabac5e197d95bb30c3d47bd61c
MD5 2aa6f3a54a088dfa0b6f59e47c831246
BLAKE2b-256 3ad4635a2a47a7de8f19acb8e0bf649d74b6e77d1b9997405a72790f665a6813

See more details on using hashes here.

Provenance

The following attestation bundles were made for cognix_ai-0.1.1.tar.gz:

Publisher: pypi-publish.yml on golemgamer/cognix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: cognix_ai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cognix_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e0cc7721d8e0b8d14c20e6c0e4af85e0346c653d4916eabd47a425f46efcc26
MD5 67055dacd557d89f4fe7881352e68019
BLAKE2b-256 fe97300e787c34949a5ce5082cccf7209b7f03a4d128f46d7c9842ef6e7fca9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cognix_ai-0.1.1-py3-none-any.whl:

Publisher: pypi-publish.yml on golemgamer/cognix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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