Metadata-Version: 2.4
Name: rift-audit
Version: 0.1.1
Summary: Reduced Inference Fast Transformer (RIFT) audit tool — measures inference efficiency in Transistor Flip Equivalents
Author-email: "QuanTM.ai" <rift@quantm.ai>
License-Expression: MIT
Project-URL: Homepage, https://quantm.ai
Project-URL: Repository, https://github.com/justinm3434/rift-audit
Keywords: inference,efficiency,transformer,audit,TFE,quantization
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.0
Requires-Dist: numpy>=1.24
Requires-Dist: tabulate>=0.9
Provides-Extra: transformers
Requires-Dist: transformers>=4.30; extra == "transformers"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: transformers>=4.30; extra == "dev"
Dynamic: license-file

# RIFT Audit Tool

**Reduced Inference Fast Transformer** audit tool — measures inference efficiency in Transistor Flip Equivalents (TFE) across CMOS, Photonic, and Quantum substrates.

Part of the [Blundin Space RIFT Competition](https://quantm.ai/competition) by QuanTM.ai.

## Install

```bash
pip install rift-audit

# With HuggingFace model support (required for most models):
pip install rift-audit[transformers]
```

### From source

```bash
git clone https://github.com/justinm3434/rift-audit.git
cd rift-audit
pip install -e ".[transformers,dev]"
```

## Quick Start

### CLI

```bash
# Audit GPT-2 from HuggingFace
rift-audit gpt2 --hellaswag-acc 30.0 --val-loss 3.28

# Save signed JSON report (required for submission)
rift-audit gpt2 --hellaswag-acc 30.0 --val-loss 3.28 --output report.json

# Custom sequence length
rift-audit gpt2 --hellaswag-acc 30.0 --val-loss 3.28 --seq-len 256
```

The tool will output something like:

```
Computing model weight hash...
Model hash: a3f8c1d2e4b5...
Auditing gpt2 (seq_len=128, device=cpu)...
Report saved to report.json (signed)
```

### Python API

```python
import torch
from transformers import AutoModelForCausalLM
from rift_audit import RIFTAuditor, compute_rift_scores

# Load model
model = AutoModelForCausalLM.from_pretrained("gpt2")
model.eval()

# Create dummy input
input_ids = torch.randint(0, 50257, (1, 128))

# Audit
auditor = RIFTAuditor()
result = auditor.audit(model, input_ids, model_name="gpt2")

# Score
scores = compute_rift_scores(result, hellaswag_accuracy=30.0, validation_loss=3.28)

print(f"RIFT-Silicon:   {scores.silicon:.4f}")
print(f"RIFT-Photonic:  {scores.photonic:.4f}")
print(f"RIFT-Quantum:   {scores.quantum:.4f}")
print(f"RIFT-Universal: {scores.universal:.4f}")
```

## Scoring

```
RIFT Score = (HellaSwag_accuracy × 1000) / log10(TFE_per_token)
```

Higher is better. The numerator rewards intelligence. The denominator penalizes thermodynamic cost on a log scale.

### Leaderboard Categories

| Category | TFE Table | Description |
|:--|:--|:--|
| RIFT-Silicon | v1.0 (CMOS) | Current hardware. Win this today. |
| RIFT-Photonic | v2.0 (Photonic) | Design for the substrate that's coming. |
| RIFT-Quantum | v3.0 (Quantum) | The long game. Radical architectures welcome. |
| RIFT-Universal | Geometric mean | The overall champion. |

## Report Integrity

Every report generated by `rift-audit` is **cryptographically signed** using HMAC-SHA256 keyed with a SHA-256 hash of the model's weights. This prevents score tampering — any modification to the JSON invalidates the signature.

### Verify a report (signature only)

```bash
rift-verify report.json
```

### Full verification (signature + model weights)

```bash
rift-verify report.json --model gpt2
```

Example output:

```
============================================================
  RIFT REPORT VERIFICATION — Full (signature + model hash)
============================================================

  RESULT: PASS
  Signature valid:    True
  Model hash matches: True
  Reason: Signature valid and model hash matches
============================================================
```

### Python API

```python
from rift_audit import verify_report, compute_model_hash

# Signature-only verification
result = verify_report(report)
print(result["valid"])        # True/False
print(result["reason"])

# Full verification (requires model)
from rift_audit.integrity import verify_model_against_report
result = verify_model_against_report(model, report)
print(result["model_hash_matches"])
```

## TFE Conversion Table

The TFE table maps operations to equivalent transistor state transitions — a substrate-agnostic measure of computational thermodynamic cost. Values are calibrated against published energy data (Horowitz 2014 ISSCC, Stillmaker & Baas 2017).

See the full table and methodology at [quantm.ai/competition](https://quantm.ai/competition).

## Qualifying Requirements

To appear on the leaderboard, submissions must meet:

| Metric | Threshold |
|:--|:--|
| HellaSwag accuracy | ≥ 30.0% |
| OpenWebText validation loss | ≤ 3.28 |

## Submission

Submit to [rift@quantm.ai](mailto:rift@quantm.ai) with subject `[RIFT Submission] Your Model Name`. See [quantm.ai/submit](https://quantm.ai/submit) for the full guide.

## License

MIT
