Skip to main content
This section explains how to integrate the SDK into different environments, handle request/response capture, and customize exported data.

Core Concepts

  • OneXMonitor: central object that configures the exporter and framework-specific adapters.
  • Adapters: attach framework-specific instrumentation (PyTorch, TensorFlow, JAX).
  • Exporter: batches signals and sends them to ingestion endpoints asynchronously.
  • Request context: optional helper to capture raw request payloads and final application responses.

Typical Flow

  1. Instantiate OneXMonitor.
  2. Call monitor.watch(model) for each model you want to instrument.
  3. (Optional) Wrap incoming requests with monitor.request_context(...) to tag raw input + application response.
  4. Call monitor.stop() when your application shuts down.

Basic Example (PyTorch)

For all config options and OneXMonitor parameters, see the Configuration Reference.

Why the request context?

  • Adds a raw block to the request payload event (your original JSON, not just tensors)
  • Emits an application-response event alongside the automatic model-output event
  • Reuses the same request_id for all neural signals, request payload, and response records

Attention metrics (BERT, GPT, ViT)

To capture attention signals (entropy per head, max/mean attention, head agreement) for Attention Health assessment, call the model with output_attentions=True:
GPT models require output_attentions=True on the forward pass for attention weights to be available.

Enabling or disabling request/response capture

By default, the SDK sends both request payloads (model inputs) and response payloads (model outputs, application responses) to the platform, in addition to neural signals. You can disable either:
Neural signals are always sent to /api/signals/batch regardless of these settings. Use this when you want to reduce data volume or avoid sending sensitive input/output to the platform.

Manual Instrumentation

If you can’t call monitor.request_context, you can drive the adapter manually:

Graceful Shutdown