OpenPay (1 crate, 2487 LOC, 33 tests)
op-fraud-graph Graph-based fraud detection. EntityKind (card/email/
device/IP/address/phone/BIN+last4/account) with
canonicalization + hashed EntityKey + billing↔shipping
mismatch detection. Adjacency-list FraudGraph with
idempotent upsert + edge-merge. Double-hashing Bloom
filter (capacity+FPR-sized). Union-find connected
components. PageRank with dangling-sink handling.
Louvain community detection. Shared-instrument hub
rings. Sliding ring-buffer velocity counters. Synthetic
identity heuristics (freshness + heavy-use + mail-drop).
Structuring / smurfing / mule-chain DFS. EntityRisk +
TransactionRisk + RiskBand combiner.
Smart Byte (1 crate, ~1844 LOC, 44 tests)
smart-byte-ilp Interledger Protocol v4. OER codec (length-determinant,
var-octet-string, BE u32/u64). Prepare/Fulfill/Reject
packet roundtrip with all 19 IL-RFC-27 reject codes.
SHA-256 Condition + Fulfillment with constant-time
verify. ILP address validator (7 schemes, 1-128 char
segments, 1023-byte cap, segment-aligned prefix match).
STREAM (15 frame types). BTP. SPSP payment-pointer
resolver. Open Payments API. Longest-prefix routing
Connector with fixed-point quote conversion + balance +
rate-limit checks.
EOC (1 crate, 1921 LOC, 36 tests)
eoc-quantize Quantization primitives. int8 (symmetric/asymmetric
with zero-inclusion fix), int4 (GPTQ + AWQ group quant),
int2 (BitNet), fp8 (E4M3/E5M2), nf4 (QLoRA). GGUF v3
header parse. safetensors read sketch. Calibration
datasets + per-channel scales. KV-cache quant. Energy
tradeoff curves (joules-per-token across schemes).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
//! NF4 distribution test — the published levels must satisfy the
|
|
//! invariants used by QLoRA: 16 distinct points, symmetric extremes at
|
|
//! ±1, sorted ascending, and containing exactly one zero.
|
|
|
|
use eoc_quantize::nf4::NF4_LEVELS;
|
|
|
|
#[test]
|
|
fn has_sixteen_levels() {
|
|
assert_eq!(NF4_LEVELS.len(), 16);
|
|
}
|
|
|
|
#[test]
|
|
fn endpoints_are_unit_magnitude() {
|
|
assert!((NF4_LEVELS[0] - (-1.0)).abs() < 1e-6);
|
|
assert!((NF4_LEVELS[15] - 1.0).abs() < 1e-6);
|
|
}
|
|
|
|
#[test]
|
|
fn strictly_increasing() {
|
|
for w in NF4_LEVELS.windows(2) {
|
|
assert!(w[1] > w[0], "NF4 not strictly increasing: {w:?}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn contains_zero() {
|
|
assert!(NF4_LEVELS.iter().any(|&v| v == 0.0));
|
|
}
|
|
|
|
#[test]
|
|
fn distribution_has_more_resolution_near_zero() {
|
|
// The published NF4 spacing is denser near zero than near the
|
|
// tails (because the standard normal density is denser near zero).
|
|
let near_zero = (NF4_LEVELS[8] - NF4_LEVELS[7]).abs();
|
|
let tail = (NF4_LEVELS[15] - NF4_LEVELS[14]).abs();
|
|
assert!(
|
|
near_zero < tail,
|
|
"expected denser packing near zero, got near_zero={near_zero}, tail={tail}"
|
|
);
|
|
}
|