Get up and running with Keys & Caches in under 5 minutes! Find the true bottlenecks, errors, and performance optimizations previously hidden or hard to discover in your ML stack - from PyTorch down to the GPU - with the help of AI.

Prerequisites

Before getting started, ensure you have the following installed:
  • Python 3.12+ (Python 3.12+ required)
  • PyTorch installed in your environment (for model profiling features)
  • Basic familiarity with PyTorch and command line

Installation

Install via pip

pip install kandc

Verify Installation

python -c "import kandc; print(f'kandc v{kandc.__version__} installed successfully')"
You should see something like: kandc v0.0.22 installed successfully

Quick Start

Copy and paste this realistic transformer example that shows experiment tracking and PyTorch profiling with detailed performance analysis:
import time
import random
import torch
import torch.nn as nn
import kandc

@kandc.capture_model_class(model_name="SimpleTransformer")
class SimpleTransformer(nn.Module):
    def __init__(self, input_dim=32, seq_len=16, d_model=64, nhead=4, num_layers=2, num_classes=10):
        super().__init__()
        self.input_dim = input_dim
        self.seq_len = seq_len
        self.d_model = d_model

        self.input_proj = nn.Linear(input_dim, d_model)
        self.pos_embedding = nn.Parameter(torch.zeros(1, seq_len, d_model))

        encoder_layer = nn.TransformerEncoderLayer(d_model=d_model, nhead=nhead, batch_first=True)
        self.transformer = nn.TransformerEncoder(encoder_layer, num_layers=num_layers)

        self.head = nn.Sequential(
            nn.LayerNorm(d_model),
            nn.Linear(d_model, num_classes)
        )

    def forward(self, x):
        x = self.input_proj(x)
        x = x + self.pos_embedding
        x = self.transformer(x)
        x = x.mean(dim=1)
        x = self.head(x)
        return x

def main():
    print("🚀 Simple kandc Example")

    run = kandc.init(
        project="optimize-transformer",
        name="test-run-1",
    )
    print("✅ Using existing authentication")

    model = SimpleTransformer()
    data = torch.randn(32, 16, 32)

    print("📊 Running model forward pass...")
    output = model(data)
    loss = output.mean()

    @kandc.timed(name="random_wait")
    def random_wait():
        print("⏳ Starting random wait...")
        time.sleep(random.random() * 2)
        print("✅ Random wait complete")

    for i in range(10):
        random_wait()

    print("📈 Logging metrics...")
    for i in range(10):
        time.sleep(0.1)
        x_value = i * 0.5
        kandc.log({"loss": loss.item(), "accuracy": random.random()}, x=x_value)

    try:
        backend_run_id = (
            getattr(run, "_run_data", {}).get("id") if getattr(run, "_run_data", None) else None
        )
    except Exception:
        backend_run_id = None
    if backend_run_id:
        print(f"✅ Run ID: {backend_run_id}")
        print("✅ API client initialized")
    else:
        print(f"✅ Local Run ID: {run.id}")
        print("⚠️ Backend run not created; operating offline")

    kandc.finish()

    print("✅ Done! Check your dashboard for results.")

if __name__ == "__main__":
    main()

What Happens When You Run This?

1

Authentication

First time users will see a browser open for sign-in
2

Project Creation

kandc creates your project on the backend
3

Run Tracking

Your run is created and tracked in real-time
4

PyTorch Profiling

The @capture_model_class decorator automatically captures detailed GPU/CPU performance metrics, memory usage, and tensor shapes
5

Timing Capture

The @timed decorator captures execution time for your custom functions
6

Metrics Logging

Your metrics are automatically saved and synced
7

Chrome Trace Analysis

PyTorch profiler traces are exported as Chrome traces viewable in Perfetto UI for detailed performance analysis
8

Dashboard

Your browser opens to show live results, trace artifacts, and AI-powered performance insights
9

Data Sync

All data is synced to the cloud for analysis

Authentication

kandc uses browser-based authentication for security and ease of use.

First Time Setup

python your_script.py
When you run kandc.init() for the first time:
1

Browser opens

A browser window opens to the authentication page
2

Sign in

Sign in with Google or GitHub
3

API key saved

Your API key is automatically saved to ~/.kandc/settings.json
4

Future runs

Future runs use the saved credentials

Next Steps


Need help? Check out our examples or reach out for support.