CI / test (push) Successful in 45s
Everything here works without GPUs and is covered by tests. The control plane connection is not built yet, so llmgw agent itself is still a stub and the phase exit criterion is not met. - discovery: IB from /sys/class/infiniband, parsing the formats sysfs actually uses and telling native InfiniBand from RoCE; GPUs via nvidia-smi, the cgo-free path, with health flags for uncorrected ECC and memory already held by another process. A node without IB is not an error, it is a single-node island. - engines: vLLM and SGLang command and environment construction, kept free of process handling so it stays testable. The NCCL environment is the part the plan marks critical: NCCL_IB_HCA lists only the chosen fabric's adapters, because leaving it open lets NCCL pick an adapter on a fabric where the peer is unreachable, and the job then hangs instead of failing. - validation before launch: no mixed GPU types in a tensor-parallel group, the node/GPU/TP arithmetic has to add up, and fp8 is refused below compute capability 8.9 rather than silently falling back to a slower path. - supervisor: process groups, because engines fork workers that hold GPU memory and outlive a signal sent only to the leader; a bounded log tail, since engine output is the only diagnosis when loading fails; Starting separate from Loading, because a 70B model legitimately takes minutes; and orphan adoption through pid files fingerprinted with the command line, since pids get reused and adopting an unrelated process is worse than leaking the original. - readiness is two questions: /health says the process is up, /v1/models says the weights loaded. Routing on /health alone sends traffic into a loading model. - llmgw agent inventory reports what the scheduler would see on a node. One plan correction: GPU class sizes come from the driver in GiB, which does not always match the marketing name. An L40S is sold as 48GB and reports 44.99 GiB, so its class is l40s-45g, not l40s-48g. Consistency matters more than matching the box, because that number decides whether a model fits. Plan §2 and §5.1 updated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
126 lines
3.7 KiB
Go
126 lines
3.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"text/tabwriter"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/agent/discovery"
|
|
)
|
|
|
|
func newAgentCmd() *cobra.Command {
|
|
var configPath string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "agent",
|
|
Short: "Node agent: discovery and engine supervision (phase 2)",
|
|
Long: "Runs on every GPU node. It discovers the hardware, starts and supervises\n" +
|
|
"inference engines, and reports to the control plane.\n\n" +
|
|
"The control plane connection is not built yet, so for now the useful\n" +
|
|
"subcommand is `agent inventory`.",
|
|
RunE: func(_ *cobra.Command, _ []string) error {
|
|
return errNotImplemented
|
|
},
|
|
}
|
|
cmd.Flags().StringVar(&configPath, "config", "agent.yaml", "configuration file")
|
|
cmd.AddCommand(newInventoryCmd())
|
|
return cmd
|
|
}
|
|
|
|
func newInventoryCmd() *cobra.Command {
|
|
var (
|
|
asJSON bool
|
|
smiBin string
|
|
ibRoot string
|
|
skipGPU bool
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "inventory",
|
|
Short: "Show this node's GPUs and InfiniBand adapters",
|
|
Long: "Reports what the scheduler would see on this node: GPU classes, health,\n" +
|
|
"and the fabric each adapter is attached to.\n\n" +
|
|
"Run it before adding a node to the cluster — it is the fastest way to find\n" +
|
|
"a card another process is already using, or a port with no subnet manager.",
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
inv := discovery.Inventory{Source: "nvidia-smi"}
|
|
|
|
if !skipGPU {
|
|
gpus, err := discovery.DiscoverGPUsSMI(cmd.Context(), smiBin)
|
|
if err != nil {
|
|
// Not fatal: a node with no GPUs still has IB worth showing,
|
|
// and the error itself is the useful output.
|
|
fmt.Fprintf(os.Stderr, "GPU discovery failed: %v\n", err)
|
|
inv.Source = "unavailable"
|
|
}
|
|
inv.GPUs = gpus
|
|
}
|
|
|
|
hcas, err := discovery.DiscoverIB(ibRoot)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
inv.HCAs = hcas
|
|
|
|
if asJSON {
|
|
enc := json.NewEncoder(os.Stdout)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(inv)
|
|
}
|
|
printInventory(inv)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
f := cmd.Flags()
|
|
f.BoolVar(&asJSON, "json", false, "emit JSON")
|
|
f.StringVar(&smiBin, "nvidia-smi", "", "path to nvidia-smi")
|
|
f.StringVar(&ibRoot, "ib-root", discovery.SysfsRoot, "sysfs InfiniBand directory")
|
|
f.BoolVar(&skipGPU, "no-gpu", false, "skip GPU discovery")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func printInventory(inv discovery.Inventory) {
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
|
|
|
fmt.Fprintf(w, "GPUs (%d)\n", len(inv.GPUs))
|
|
if len(inv.GPUs) == 0 {
|
|
fmt.Fprintln(w, " none")
|
|
} else {
|
|
fmt.Fprintln(w, " IDX\tCLASS\tNAME\tMEM\tCC\tHEALTH")
|
|
for _, g := range inv.GPUs {
|
|
health := "ok"
|
|
if !g.Health.OK() {
|
|
health = g.Health.Problems[0]
|
|
}
|
|
fmt.Fprintf(w, " %d\t%s\t%s\t%d MiB\t%s\t%s\n",
|
|
g.Index, g.Class(), g.Name, g.MemoryTotalMB, g.ComputeCapability, health)
|
|
}
|
|
fmt.Fprintf(w, " classes: %v\n", inv.Classes())
|
|
}
|
|
|
|
fmt.Fprintf(w, "\nInfiniBand adapters (%d)\n", len(inv.HCAs))
|
|
if len(inv.HCAs) == 0 {
|
|
// Worth stating plainly: such a node is its own single-node island and
|
|
// can never host a multi-node replica.
|
|
fmt.Fprintln(w, " none — this node cannot host multi-node replicas")
|
|
} else {
|
|
fmt.Fprintln(w, " HCA\tPORT\tSTATE\tRATE\tLINK\tGID PREFIX\tNUMA")
|
|
for _, h := range inv.HCAs {
|
|
for _, p := range h.Ports {
|
|
fmt.Fprintf(w, " %s\t%d\t%s\t%d Gb/s\t%s\t%s\t%d\n",
|
|
h.Name, p.Num, p.State, p.RateGbps, p.LinkLayer, p.GIDPrefix, h.NUMANode)
|
|
}
|
|
}
|
|
fmt.Fprintln(w, "\n Fabric identity is not derived from the GID prefix by default:")
|
|
fmt.Fprintln(w, " OpenSM's default is fe80:: on every fabric, so a shared prefix proves")
|
|
fmt.Fprintln(w, " nothing. Label fabrics explicitly in agent.yaml (plan §5.2).")
|
|
}
|
|
|
|
_ = w.Flush()
|
|
}
|