Sending Inference Requests
Install client dependencies first:
7.1 Standard Fraud Scoring — CLI Client
The client script is written to your output directory at the end of training:
Run it with the model_config.json from your training output and your test data directory:
The --data_path directory must have the same nodes/ and edges/ layout as your training data with identical filenames and feature column counts. Requirements:
- Node CSVs: same filenames and column order as
training_data/nodes/. Feature count must match exactly. - Edge CSVs: same filenames and column order as
training_data/edges/. All edge types (including context edges likeB_to_C.csv) must be present for k-hop subgraph sampling to work correctly — not just the predicted edge type. - Label CSV: required (e.g.
edges/account_transacts_merchant_label.csv). The client computes Precision, Recall, and F1 against ground truth labels. - NP: all rows in the label node CSV are scored as inference targets; no mask file is needed in
test_gnn/.
The required test_gnn/ directory structure is described in Section 3.1.
What the client does, step by step:
- Reads
model_config.jsonto learn the graph schema (node types, feature dimensions, edge type name, decision threshold,num_neighbors). - Loads all node and edge CSVs from
--data_pathinto memory. - Builds adjacency structures for client-side BFS subgraph sampling (when
num_neighborsis present inmodel_config.json). - For each batch of query edges: samples a subgraph using BFS from both endpoints of each query edge (using the trained
num_neighborshop counts), then sends the sampled subgraph plus the batch endpoints to Triton’sfraud_pipelineensemble using gRPC. With--no_sampling, sends the full graph as context instead. - Receives a
[N, 1]float32 tensor containing P(fraud) for each query edge. - Thresholds at
val_thresholdfrommodel_config.json. - Aggregates predictions, computes precision/recall/F1 against ground truth labels.
- Prints a latency summary and sample fraud detections.
Sample output:
All CLI flags:
7.1b Node Prediction Client (GNN_XGBoost_NP)
When you trained with kind: GNN_XGBoost_NP, use client_np.py instead of client.py. It targets the np_fraud_pipeline ensemble and expects model_config_np.json:
Key differences from the EP client:
CLI flags are identical: --url, --model_config, --data_path, --batch_size, --warmup_batches, --explain, --explain_limit, --microbatch_delay_ms, --no_sampling.
client_saved_emb.py — Hybrid Saved-Embedding Client
Use this client when training was run with save_node_embeddings: true. It routes each edge through a fast memmap lookup for known nodes and falls back to the GNN for novel nodes.
Example output:
Unlike client.py, this client prints separate metrics for the KNOWN path (memmap) and NOVEL path (GNN fallback):
A cold-start warning fires when the novel-node percentage exceeds 10%: ⚠ >10% novel nodes — consider re-training to refresh embeddings.
Key CLI flags:
client_production.py — Production HTTP Service and Concurrent Batch Eval
client_production.py extends the hybrid routing of client_saved_emb.py with two additional capabilities:
- Concurrent batch eval: dispatches Triton requests in parallel across multiple model instances using
ThreadPoolExecutor - Persistent HTTP service (
--serve): opens memmaps once at startup and serves requests indefinitely
Batch eval mode (no --serve):
Reports the same per-path metrics (ALL / KNOWN / NOVEL) as client_saved_emb.py, plus latency percentiles per batch.
Persistent HTTP service (--serve):
At startup, embeddings.mmap and features.mmap are opened as np.memmap(mode='r') — zero bytes copied into RAM. The OS page-cache handles demand paging. Multiple server processes can open the same file and share the underlying pages.
Endpoints:
POST /score request:
neighbors is an optional pre-built k-hop subgraph for novel nodes (one entry per directed edge: [src_global_id, dst_global_id, edge_type_stem]). Populate this from a live graph database query when novel nodes are expected. Omit for 0-hop fallback (raw features, no message passing).
POST /score response:
"path" per edge is "memmap" (known node fast path) or "gnn" (novel node fallback).
POST /explain — same request body as /score. Always runs xgb_explainer (SVS Shapley-like attribution) and llm_explainer. Returns "svs" dict (feature name → score, positive pushes toward fraud) plus "explanations" text. Add "no_llm": true to return SVS only, skipping the LLM call.
Key CLI flags:
7.2 LLM Explainability Mode
Add --explain to run a two-pass workflow. Pass 1 scores all edges with fraud_pipeline. Pass 2 sends the top detected fraud edges (sorted by descending probability) individually to fraud_pipeline_explained.
Pass 2 workflow (per fraud edge):
gnn_embedder: re-computes the edge embedding (same as pass 1).xgb_explainer: runs XGBoost inference + Captum Shapley Value Sampling. Outputs the fraud probability, the raw edge embedding, and asvs_attrsvector of per-feature-group attributions.llm_explainer: assembles the top-8 feature groups (by absolute SVS attribution) into a structured prompt, calls the LLM API, and returns a plain-language explanation string.
Typical explanation output:
What the SVS Shapley Values represent:
Shapley values answer the question: “how much did each feature group contribute to changing the prediction from the baseline (average legitimate transaction) to this specific prediction?” A positive value means the feature pushed the model toward predicting fraud; a negative value means it pulled toward legitimate. The LLM sees the top-8 groups and their human-readable descriptions (e.g., “transaction amount = $4,823.50”).
Production guidance for explanations:
- Explanations are generated using an external API call per fraud edge. At peak loads, use
--explain_limitto cap the number of explanations and avoid rate limits. - The LLM model choice affects explanation quality significantly. A larger model (70B parameters) produces more nuanced, accurate reasoning but at higher latency and cost.
- Explanations are advisory only. The fraud decision is made by XGBoost; the LLM only narrates what the model already decided.
7.3 Micro-Batch Gateway Simulation
Financial systems often cannot score transactions one by one; they queue incoming transactions and flush when a maximum batch size or maximum wait time is reached. Use --microbatch_delay_ms to simulate this gateway model and measure end-to-end per-transaction latency.
This simulates: transactions arrive continuously; the gateway flushes when 256 edges accumulate or 50 ms elapses.
Sample output:
In this example: the batch RTT is ~9.4 ms, but each transaction also waits in the queue for up to 50 ms. The average end-to-end latency per transaction is ~35 ms. To reduce this, either reduce microbatch_delay_ms (accept smaller batches and flush more often) or increase batch_size (larger batches amortise the RTT across more transactions).
7.4 Programmatic Python Client
For integration into your own Python application (rather than using the CLI), use tritonclient directly.
--no_sampling). This is simple but does not scale to production-sized graphs. For production use, reproduce the BFS subgraph sampling from client.py’s _sample_ep_subgraph function, which limits each request to the sampled neighbourhood of the query edges.7.5 REST API Using curl
Triton also exposes an HTTP REST API on port 8000, which can be useful for quick testing without a Python environment.
7.6 Interpreting Results and Setting Thresholds
The Fraud Probability
The output of fraud_pipeline is a [N, 1] float32 tensor:
- Column 0: P(fraud) — probability this edge is fraudulent.
P(legitimate) = 1 − P(fraud) if needed.
Using the Pre-Calibrated Threshold
The pipeline selects a decision threshold during training by maximising the F1 score on the validation set. This threshold is stored in model_config.json as val_threshold and used automatically by client.py. For most deployments, this threshold is a good starting point.
Adjusting the Threshold for Your Business Requirements
The optimal threshold depends on the relative cost of:
- False positives (FP): Legitimate transactions flagged as fraud. Customer friction, manual review cost.
- False negatives (FN): Fraudulent transactions missed. Direct financial loss + potential regulatory penalties.
To evaluate different thresholds without retraining:
Once you have chosen a new threshold, update it in the deployment by modifying model_config.json in the model repository and restarting (or hot-reloading) the gnn_embedder model in Triton: