straggler

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package straggler detects slow and intermittent GPU stragglers across single and multi-node clusters without PyTorch or cgo.

Each GPU runs four independent workloads concurrently—a transformer-like step loop with idle gaps (WorkloadStep), sustained BF16 matrix multiplication (WorkloadMatmul), device-to-device memory copy (WorkloadCopy), and an SM streaming vector-add kernel (WorkloadStream)—recording per-window throughput, duration, clock, power, temperature, and throttle telemetry in fixed time windows (default 2s).

Analyze evaluates collected GPURun samples using modified z-scores (0.6745 * (x - median) / MAD) against peer GPUs on the same node, against each GPU's own median window (catching intermittent thermal or power-cap stragglers), and against the cluster median node (or saved baseline runs loaded via ReadBaselineJSON for 1–2 node clusters). Consensus aggregates repeated runs to separate persistent stragglers from one-off noise.

FormatReport renders an RMA-ready tabular summary listing flagged GPUs by UUID, board serial, and PCI bus ID. GatherServer and SubmitRuns provide lightweight stdlib HTTP result gathering across nodes without torchrun.

Zero values of Thresholds and RunConfig do not enable default limits; start from DefaultThresholds and DefaultRunConfig. Live GPU execution via NewPuregoBackend requires Linux with CUDA, cuBLASLt, NVRTC, and NVML libraries; on other platforms it returns an error wrapping github.com/tmc/lib/nvidia/x/cuda.ErrUnsupported.

This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.

Index

Examples

Constants

View Source
const (
	ThrottleGpuIdle                   uint64 = 0x0000000000000001
	ThrottleApplicationsClocksSetting uint64 = 0x0000000000000002
	ThrottleSwPowerCap                uint64 = 0x0000000000000004
	ThrottleHwSlowdown                uint64 = 0x0000000000000008
	ThrottleSyncBoost                 uint64 = 0x0000000000000010
	ThrottleSwThermalSlowdown         uint64 = 0x0000000000000020
	ThrottleHwThermalSlowdown         uint64 = 0x0000000000000040
	ThrottleHwPowerBrakeSlowdown      uint64 = 0x0000000000000080
	ThrottleDisplayClockSetting       uint64 = 0x0000000000000100
)

NVML clock throttle / event bitmask constants mirrored from NVML so throttle decoding works on every platform (including macOS offline analysis).

View Source
const DefaultUnflaggedRows = 12

DefaultUnflaggedRows is the default number of healthy GPU rows shown when showAll is false.

Variables

This section is empty.

Functions

func DecodeOtherLimits

func DecodeOtherLimits(mask uint64) []string

DecodeOtherLimits returns human-readable names for non-power-cap throttling bits set in mask. Benign states (gpu_idle, applications_clocks_setting, display_clock_setting) and sw_power_cap (reported separately) are omitted.

func FormatConsensus

func FormatConsensus(w io.Writer, c *ConsensusReport) error

FormatConsensus writes a concise summary of a multi-repeat ConsensusReport.

func FormatReport

func FormatReport(w io.Writer, rep *Report, showAll bool) error

FormatReport writes a human-readable summary of rep to w, including the node-vs-median-node table, the per-GPU telemetry table, and an RMA summary listing flagged GPUs by UUID, serial, and PCI bus ID. When showAll is false, at most DefaultUnflaggedRows healthy GPUs are shown.

func FormatReportWithLimit

func FormatReportWithLimit(w io.Writer, rep *Report, unflaggedLimit int) error

FormatReportWithLimit formats rep to w, showing all flagged GPUs plus at most unflaggedLimit healthy GPUs (negative means unlimited).

func MAD

func MAD(xs []float64) float64

MAD returns the median absolute deviation from the median of xs. It returns 0 for an empty slice.

func Median

func Median(xs []float64) float64

Median returns the median of xs without modifying the input slice. It returns 0 for an empty slice.

func ModifiedZScore

func ModifiedZScore(x, median, mad float64) float64

ModifiedZScore returns the modified z-score 0.6745 * (x - median) / mad. When mad is zero, negative, or non-finite, it returns 0 rather than NaN or Inf.

func Percentile

func Percentile(xs []float64, p float64) float64

Percentile returns the linear-interpolated p-th percentile (0 <= p <= 100) of xs without modifying the input slice. It returns 0 for an empty slice.

func SubmitRuns

func SubmitRuns(ctx context.Context, addr, token, node string, runs []GPURun) error

SubmitRuns posts a worker node's runs to a GatherServer at addr (host:port or http://host:port).

func WriteJSON

func WriteJSON(w io.Writer, snap *JSONSnapshot) error

WriteJSON encodes snap as indented JSON to w.

func WriteJSONFile

func WriteJSONFile(path string, snap *JSONSnapshot) error

WriteJSONFile writes snap to path atomically via a temporary file rename.

Types

type ConfirmedGPU

type ConfirmedGPU struct {
	Device     DeviceIdentity `json:"device"`
	Workload   Workload       `json:"workload"`
	Reason     Reason         `json:"reason"`
	FlagCount  int            `json:"flag_count"`
	Repeats    int            `json:"repeats"`
	MeanP90Pct float64        `json:"mean_p90_pct"`
	MeanZ      float64        `json:"mean_z"`
}

ConfirmedGPU aggregates a GPU's flagging history across repeated runs.

type ConfirmedNode

type ConfirmedNode struct {
	Node       string   `json:"node"`
	Workload   Workload `json:"workload"`
	FlagCount  int      `json:"flag_count"`
	Repeats    int      `json:"repeats"`
	MeanP90Pct float64  `json:"mean_p90_pct"`
}

ConfirmedNode aggregates a node's slow_node flagging history across repeats.

type ConsensusReport

type ConsensusReport struct {
	Repeats        int             `json:"repeats"`
	ConfirmedGPUs  []ConfirmedGPU  `json:"confirmed_gpus,omitempty"`
	TransientGPUs  []ConfirmedGPU  `json:"transient_gpus,omitempty"`
	ConfirmedNodes []ConfirmedNode `json:"confirmed_nodes,omitempty"`
	TransientNodes []ConfirmedNode `json:"transient_nodes,omitempty"`
}

ConsensusReport separates stragglers seen in every repeat from transient spikes.

func Consensus

func Consensus(reports []*Report) *ConsensusReport

Consensus aggregates repeated Analyze reports (e.g. from --repeat N) and separates GPUs and nodes flagged in every repeat from transient one-off spikes.

type DeviceIdentity

type DeviceIdentity struct {
	Node     string `json:"node"`
	GPU      int    `json:"gpu"`
	Name     string `json:"name,omitempty"`
	UUID     string `json:"uuid,omitempty"`
	Serial   string `json:"serial,omitempty"`
	PCIBusID string `json:"pci_bus_id,omitempty"`
}

DeviceIdentity uniquely identifies a GPU for reporting and RMA tracking.

func (DeviceIdentity) Key

func (d DeviceIdentity) Key() string

Key returns a stable identifier combining node name and GPU index.

type FlaggedGPU

type FlaggedGPU struct {
	Device    DeviceIdentity `json:"device"`
	Workload  Workload       `json:"workload"`
	Reason    Reason         `json:"reason"`
	P90Pct    float64        `json:"p90_pct"`
	ModifiedZ float64        `json:"modified_z"`
	Detail    string         `json:"detail,omitempty"`
}

FlaggedGPU records one straggler detection for a GPU on a specific workload.

type FlaggedNode

type FlaggedNode struct {
	Node      string   `json:"node"`
	Workload  Workload `json:"workload"`
	P90Pct    float64  `json:"p90_pct"`
	ModifiedZ float64  `json:"modified_z"`
	Detail    string   `json:"detail,omitempty"`
}

FlaggedNode records a slow_node detection for a node on a specific workload.

type GPURun

type GPURun struct {
	Device   DeviceIdentity    `json:"device"`
	Workload Workload          `json:"workload"`
	Windows  []WindowSample    `json:"windows"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

GPURun holds all window samples collected for one GPU on one workload.

func RunAll

func RunAll(ctx context.Context, backend WorkloadBackend, cfg RunConfig) ([]GPURun, error)

RunAll discovers GPUs from backend, filters them by cfg.Devices (when non-empty), and runs each enabled workload concurrently across all selected GPUs (one goroutine per GPU with no inter-GPU communication).

type GPUSummary

type GPUSummary struct {
	Device    DeviceIdentity             `json:"device"`
	Workloads map[Workload]WorkloadStats `json:"workloads"`
	Flags     []FlaggedGPU               `json:"flags,omitempty"`
}

GPUSummary aggregates per-workload stats and flags for one GPU.

type GatherServer

type GatherServer struct {
	// contains filtered or unexported fields
}

GatherServer is a lightweight stdlib HTTP coordinator that collects GPURun batches from worker nodes without torchrun or MPI.

func NewGatherServer

func NewGatherServer(addr, token string, expectedNodes int) (*GatherServer, error)

NewGatherServer starts listening on addr (use "127.0.0.1:0" for an ephemeral port) and accepts submissions until expectedNodes distinct nodes have reported. If token is non-empty, callers must present "Authorization: Bearer <token>".

func (*GatherServer) AddLocal

func (g *GatherServer) AddLocal(node string, runs []GPURun)

AddLocal records runs from the coordinator node itself without an HTTP hop.

func (*GatherServer) Addr

func (g *GatherServer) Addr() string

Addr returns the listener's bound network address (host:port).

func (*GatherServer) Close

func (g *GatherServer) Close() error

Close shuts down the gather HTTP server and closes its listener.

func (*GatherServer) Wait

func (g *GatherServer) Wait(ctx context.Context) ([]GPURun, error)

Wait blocks until all expected nodes have submitted or ctx is cancelled, returning all collected runs in deterministic node order.

type JSONSnapshot

type JSONSnapshot struct {
	Version   int       `json:"version"`
	Timestamp time.Time `json:"timestamp"`
	Config    RunConfig `json:"config"`
	Runs      []GPURun  `json:"runs"`
	Report    *Report   `json:"report,omitempty"`
}

JSONSnapshot is the serialized format for --json and --baseline files.

func ReadBaselineFile

func ReadBaselineFile(path string) (*JSONSnapshot, error)

ReadBaselineFile reads and decodes a JSONSnapshot from path.

func ReadBaselineJSON

func ReadBaselineJSON(r io.Reader) (*JSONSnapshot, error)

ReadBaselineJSON decodes a JSONSnapshot previously written by WriteJSON.

type NodeSummary

type NodeSummary struct {
	Node      string                         `json:"node"`
	GPUCount  int                            `json:"gpu_count"`
	Workloads map[Workload]NodeWorkloadStats `json:"workloads"`
	Flags     []FlaggedNode                  `json:"flags,omitempty"`
}

NodeSummary aggregates per-workload node-level stats and flags.

type NodeWorkloadStats

type NodeWorkloadStats struct {
	Workload             Workload `json:"workload"`
	MedianDurationMS     float64  `json:"median_duration_ms"`
	P90DurationMS        float64  `json:"p90_duration_ms"`
	DeltaVsMedianNodePct float64  `json:"delta_vs_median_node_pct"`
	ModifiedZ            float64  `json:"modified_z"`
}

NodeWorkloadStats summarizes one node's aggregate performance on one workload.

type Reason

type Reason string

Reason classifies why a GPU or node was flagged as a straggler.

const (
	// ReasonSlow indicates a GPU's p90 window is persistently slower than the
	// node median GPU in the same window.
	ReasonSlow Reason = "slow"
	// ReasonUnsteady indicates a GPU's p90 window is significantly slower than
	// its own median window, catching intermittent stragglers.
	ReasonUnsteady Reason = "unsteady"
	// ReasonSlowNode indicates a node's median GPU p90 window is significantly
	// slower than the median node across the cluster or baselines.
	ReasonSlowNode Reason = "slow_node"
)

type Report

type Report struct {
	Thresholds        Thresholds    `json:"thresholds"`
	NodeCount         int           `json:"node_count"`
	BaselineNodeCount int           `json:"baseline_node_count,omitempty"`
	Nodes             []NodeSummary `json:"nodes"`
	GPUs              []GPUSummary  `json:"gpus"`
	FlaggedGPUs       []FlaggedGPU  `json:"flagged_gpus,omitempty"`
	FlaggedNodes      []FlaggedNode `json:"flagged_nodes,omitempty"`
}

Report is the complete output of Analyze.

func Analyze

func Analyze(runs []GPURun, baselines []GPURun, thr Thresholds) (*Report, error)

Analyze evaluates runs against thresholds thr, optionally incorporating baseline runs from known-healthy nodes (useful for 1–2 node clusters).

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/obs/straggler"
)

func main() {
	var runs []straggler.GPURun
	for gpu := 0; gpu < 8; gpu++ {
		windows := make([]straggler.WindowSample, 10)
		for w := range windows {
			dur := 100.0 + float64((gpu+w)%2)*0.1
			if gpu == 5 {
				dur = 104.5 + float64(w%2)*0.1
			}
			windows[w] = straggler.WindowSample{
				WindowIndex: w,
				DurationMS:  dur,
				Rate:        950.0,
				ClockMHz:    1950,
				PowerW:      680,
				TempC:       65,
			}
		}
		runs = append(runs, straggler.GPURun{
			Device: straggler.DeviceIdentity{
				Node:     "node-0",
				GPU:      gpu,
				UUID:     fmt.Sprintf("GPU-0000-000%d", gpu),
				Serial:   fmt.Sprintf("SN100%d", gpu),
				PCIBusID: fmt.Sprintf("0000:0%d:00.0", gpu),
			},
			Workload: straggler.WorkloadStep,
			Windows:  windows,
		})
	}

	rep, err := straggler.Analyze(runs, nil, straggler.DefaultThresholds())
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	for _, f := range rep.FlaggedGPUs {
		fmt.Printf("%s gpu=%d workload=%s reason=%s uuid=%s\n",
			f.Device.Node, f.Device.GPU, f.Workload, f.Reason, f.Device.UUID)
	}
}
Output:
node-0 gpu=5 workload=step reason=slow uuid=GPU-0000-0005

type RunConfig

type RunConfig struct {
	Node           string        `json:"node,omitempty"`
	Devices        []int         `json:"devices,omitempty"`
	StepDuration   time.Duration `json:"step_duration"`
	MatmulDuration time.Duration `json:"matmul_duration"`
	CopyDuration   time.Duration `json:"copy_duration"`
	StreamDuration time.Duration `json:"stream_duration"`
	Window         time.Duration `json:"window"`
	IdleGap        time.Duration `json:"idle_gap"`
	Layers         int           `json:"layers"`
	Hidden         int           `json:"hidden"`
	SeqLen         int           `json:"seqlen"`
	MatmulSize     int           `json:"matmul_size"`
	CopyBytes      int64         `json:"copy_bytes"`
	StreamBytes    int64         `json:"stream_bytes"`
}

RunConfig configures workload execution for RunAll.

func DefaultRunConfig

func DefaultRunConfig() RunConfig

DefaultRunConfig returns the standard benchmark durations and sizes.

func (RunConfig) DurationFor

func (c RunConfig) DurationFor(w Workload) time.Duration

DurationFor returns the configured duration for workload w.

type Thresholds

type Thresholds struct {
	// OutlierZ is the minimum modified z-score required to flag a GPU as slow
	// or unsteady (default 3.5).
	OutlierZ float64 `json:"outlier_z"`
	// SlowPct is the minimum percentage slower than the node median GPU at p90
	// required to flag a GPU as slow (default 1.0).
	SlowPct float64 `json:"slow_pct"`
	// UnsteadyPct is the minimum percentage slower than a GPU's own median
	// window at p90 required to flag it as unsteady (default 1.25).
	UnsteadyPct float64 `json:"unsteady_pct"`
	// SlowNodePct is the minimum percentage slower than the median node at p90
	// required to flag a node as slow_node (default 3.0).
	SlowNodePct float64 `json:"slow_node_pct"`
}

Thresholds configures the statistical straggler detector.

func DefaultThresholds

func DefaultThresholds() Thresholds

DefaultThresholds returns the standard straggler detection thresholds.

type WindowSample

type WindowSample struct {
	WindowIndex  int     `json:"window_index"`
	DurationMS   float64 `json:"duration_ms"`
	Rate         float64 `json:"rate"` // TFLOPS for step/matmul, GB/s for copy/stream
	ClockMHz     uint32  `json:"clock_mhz,omitempty"`
	PowerW       float64 `json:"power_w,omitempty"`
	TempC        uint32  `json:"temp_c,omitempty"`
	PowerCapped  bool    `json:"power_capped,omitempty"`
	ThrottleMask uint64  `json:"throttle_mask,omitempty"`
}

WindowSample records performance and NVML telemetry for one measurement window.

type Workload

type Workload string

Workload identifies one of the four straggler benchmark workloads.

const (
	// WorkloadStep runs repeated BF16 GEMM layers separated by an idle gap to
	// reproduce training-step power-cap and boost-clock recovery cycles.
	WorkloadStep Workload = "step"
	// WorkloadMatmul runs sustained BF16 matrix multiplication via cuBLASLt.
	WorkloadMatmul Workload = "matmul"
	// WorkloadCopy runs sustained device-to-device memory copies.
	WorkloadCopy Workload = "copy"
	// WorkloadStream runs a sustained SM streaming c = a + b kernel.
	WorkloadStream Workload = "stream"
)

func AllWorkloads

func AllWorkloads() []Workload

AllWorkloads returns the four workloads in canonical reporting order.

func (Workload) Valid

func (w Workload) Valid() bool

Valid reports whether w is one of the four defined workloads.

type WorkloadBackend

type WorkloadBackend interface {
	// Devices returns the visible GPUs on this node.
	Devices(ctx context.Context) ([]DeviceIdentity, error)
	// RunWorkload executes a single workload on dev and returns its window samples.
	RunWorkload(ctx context.Context, dev DeviceIdentity, workload Workload, cfg RunConfig) (GPURun, error)
}

WorkloadBackend executes straggler workloads on GPUs. Tests can supply a deterministic in-memory implementation without CUDA hardware.

func NewPuregoBackend

func NewPuregoBackend(node string) (WorkloadBackend, error)

NewPuregoBackend initializes the purego CUDA driver and (best-effort) NVML telemetry backend on Linux without cgo.

type WorkloadStats

type WorkloadStats struct {
	Workload         Workload `json:"workload"`
	WindowCount      int      `json:"window_count"`
	MedianDurationMS float64  `json:"median_duration_ms"`
	P90DurationMS    float64  `json:"p90_duration_ms"`
	MedianRate       float64  `json:"median_rate"`
	P90Rate          float64  `json:"p90_rate"`
	SlowPct          float64  `json:"slow_pct"`
	SlowZ            float64  `json:"slow_z"`
	UnsteadyPct      float64  `json:"unsteady_pct"`
	UnsteadyZ        float64  `json:"unsteady_z"`
	MedianClockMHz   uint32   `json:"median_clock_mhz,omitempty"`
	MeanPowerW       float64  `json:"mean_power_w,omitempty"`
	MaxTempC         uint32   `json:"max_temp_c,omitempty"`
	PowerCappedPct   float64  `json:"power_capped_pct,omitempty"`
	ThrottleMask     uint64   `json:"throttle_mask,omitempty"`
	OtherLimits      []string `json:"other_limits,omitempty"`
}

WorkloadStats summarizes one GPU's performance and telemetry on one workload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL