Skip to main content

Framework-agnostic deep learning API quality verification tool

Project description

tensor-spec

PyPI - Python Version pypi PyPI - Downloads LICENSE

uv ruff Gitmoji

Overview

tensor-spec is a framework-agnostic deep learning API quality verification tool. It compares tensor operation precision across deep learning frameworks (currently PaddlePaddle vs PyTorch) using process isolation and CUDA IPC zero-copy GPU data sharing.

Features

  • Framework-agnostic -- Pluggable backend architecture supporting PaddlePaddle and PyTorch
  • Process isolation -- Each framework runs in its own subprocess to avoid CUDA/import conflicts
  • CUDA IPC zero-copy -- GPU tensor sharing via CUDA IPC handles (1000x faster than CPU roundtrip)
  • Secure config parsing -- Whitelist recursive descent parser (no eval())
  • Constraint-driven data generation -- Generate test tensors from specs with composable constraints
  • Per-API tolerance -- Configurable atol/rtol with TOML-based overrides per operator
  • Structured logging -- JSON Lines output for machine-parseable test results
  • CLI interface -- check, bench, doctor, setup, migrate, pack/unpack commands via Typer

Installation

pip install tensor-spec

Or with uv:

uv add tensor-spec

Quick Start

# Check a single case on one backend
tensor-spec check 'abs(x=Tensor.float32((2, 3)))' --target backend=torch,python=/path/to/python

# Cross-framework comparison (auto-selects reference)
tensor-spec check cases/ --target torch-cu124 --target paddle-cu124

# e2e benchmark
tensor-spec bench --mode e2e cases/ --target torch-cu124 --target paddle-cu124 --baseline torch-cu124

# NCU benchmark (artifacts default to ./.tensor-spec/bench-artifacts)
tensor-spec bench --mode ncu cases/ --target torch-cu124 --target paddle-cu124

# Dry-run validation (no execution)
tensor-spec check cases/ --target torch-cu124 --dry-run

# Environment diagnosis
tensor-spec doctor

Development

Prerequisites

  • Python >= 3.12
  • uv for dependency management
  • just for task running

Setup

just install

Common Commands

just            # List all available commands
just format     # Format code (Python + justfile)
just lint       # Run linter
just check      # Type checking (pyright)
just test       # Run all tests
just cov        # Run tests with coverage
just docs       # Serve docs locally
just ci         # Full CI check (format + check + lint + cov)

Architecture

The project follows a 10-layer modular architecture:

Layer Module Responsibility
1 spec Pure data structures for tensor specifications
2 config Secure whitelist recursive descent parser
3 datagen Constraint-driven numpy array generation
4 backend Pluggable framework backends (Paddle, PyTorch)
5 mapping API name/argument mapping between frameworks
6 compare Tensor comparison with configurable tolerance
7 tester Test execution modes (in-process, isolated)
8 worker Subprocess management and IPC protocol
9 ipc SharedMemory (CPU) and CUDA IPC (GPU) transport
10 cli Typer-based CLI entry point

Documentation

For detailed usage and API documentation, please visit our documentation site. For CLI design details, see CLI Specification.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for development setup and contribution guidelines.

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

tensor_spec-0.1.2.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

tensor_spec-0.1.2-py3-none-any.whl (57.3 kB view details)

Uploaded Python 3

File details

Details for the file tensor_spec-0.1.2.tar.gz.

File metadata

  • Download URL: tensor_spec-0.1.2.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tensor_spec-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e2ade9316e8df66fcfe7deb07d22b22b9c174fe643840fd33f4fa4489d58c4dc
MD5 0fea5e1b1dd87857861d04ccabaeeadb
BLAKE2b-256 2ba534d1ae7a2a0a612b4590992ea59d98f0da55bd3160a9a462673534d64e1b

See more details on using hashes here.

File details

Details for the file tensor_spec-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: tensor_spec-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 57.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tensor_spec-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c3df23cbb22972827c604d0a5fa19ae6a159a5f23ddc607e2e9bb6a64008ab8a
MD5 a8007ea03b3935984aa84728e2f9cebf
BLAKE2b-256 bcd82551cdfe99f861060283025945f65d5fe7f195ea42c9722bb7419a12526d

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