sparkrun Documentation

repository·main·Indexed 18 days ago

https://github.com/spark-arena/sparkrun

A command-line tool for launching and managing Docker-based LLM inference workloads on NVIDIA DGX Spark systems without Slurm or Kubernetes. It supports runtimes including vLLM, SGLang, llama.cpp, and TensorRT-LLM, and automates multi-node tensor parallelism and model distribution. The tool includes a guided setup wizard for cluster and SSH configuration, a recipe-based system for workload definitions, and an OpenAI-compatible proxy gateway. It also provides plugins for Claude Code and OpenClaw.

Tokens
71.6K
Snippets
220
Records
292
Agent score
63%

What's inside sparkrun

  1. Available Executor types in sparkrun

    main

    sparkrun supports three primary executor types for running workloads:

    SelectorClassStatusNotes
    dockerDockerExecutorStableThe default executor. Used by most launch paths.
    localLocalExecutorAlphaRuns as a native subprocess without a container. Uses a hand-coded process-group lifecycle.
    k8sK8sExecutorExperimentalDriven by kubectl run. Note that it drops many Docker-specific options.
  2. Overview of the sparkrun proxy

    main

    The sparkrun proxy is a unified, OpenAI-compatible gateway that discovers running sparkrun inference endpoints and exposes them through a single API powered by LiteLLM. It acts as a front-end for one or more inference workloads, providing:

    • Live endpoint discovery: Automatically finds running workloads using the same mechanism as sparkrun cluster status.
    • Auto-discovery: A background process that periodically re-scans and syncs models to handle drift.
    • Health checking: Validates endpoints via GET /v1/models.
    • Deduplication: Ensures endpoints reachable on multiple interfaces (e.g., management vs. ConnectX-7) are not duplicated.
    • Model aliases: Allows clients to address models by friendly names.
    • Load/unload management: Syncs the proxy with the current set of running models.

    Note on configuration updates: Because the proxy uses a generated config file as the single source of truth, applying changes (like adding a model or alias) requires rewriting the config and restarting the process. The proxy is optimized to skip the restart if the desired state already matches the disk.

  3. How recipe discovery and disambiguation works

    main

    When requesting a recipe, sparkrun follows a specific search order to locate the configuration file:

    1. @registry/recipe-name: Scoped lookup within a specific registry.
    2. URL: Fetched via HTTP/HTTPS and cached.
    3. File path: An exact path or a path with a .yaml/.yml extension.
    4. CWD scan: Scans the Current Working Directory for valid .yaml/.yml files (files must contain model, container, and a resolvable runtime).
    5. Registry search: A flat and recursive lookup performed independently for each enabled registry.

    Disambiguation

    • Across Registries: Use the @registry/name syntax to specify which registry to use.
    • Within a Registry: Use @registry/subdir/name to specify a path under the registry's recipe directory (the scope is split on the first /).
    • Ambiguity Errors: If a name matches multiple recipes within a single registry (e.g., a/foo.yaml and b/foo.yaml), sparkrun will error and provide the path-qualified names. If your terminal is a TTY, the CLI will instead provide a numbered prompt to select the correct one.

    Example error message: Recipe 'foo' is ambiguous — 2 matches in registry 'official' (@official/a/foo, @official/b/foo). Use the full name to specify.

  4. Understand the sparkrun multiplatform architecture

    main

    The sparkrun architecture is organized into several layers to support multiplatform inference workloads (NVIDIA, AMD, Intel).

    • core/: Handles hardware probing (hardware_probe.py), hardware specification (hardware.py), backend selection (backend_select.py), and the main launch orchestration (launcher.py).
    • orchestration/: Manages how workloads are executed and how communication collectives are configured.
      • Executors: Responsible for running the workload (e.g., DockerExecutor, LocalExecutor, K8sExecutor).
      • Collectives: Manages communication backends like NcclBackend (NVIDIA), RcclBackend (AMD scaffold), and HcclBackend (Intel scaffold).
    • platforms/: Provides hardware-specific plugins (e.g., DgxSparkPlatform, GenericNvidiaPlatform) that define how to match hardware, validate hosts, and select default images.
  5. How platforms are resolved

    main

    A HardwarePlatformPlugin is used to match specific hardware environments to optimized configurations.

    platforms/resolve_platform(host_hardware) iterates through a registry (_REGISTRY) and returns the first plugin whose matches() method returns true. The registry is ordered from most-specific to least-specific.

    Example Priority:

    • DgxSparkPlatform (matches model="gb10") will be selected before GenericNvidiaPlatform if the hardware is a DGX Spark node.
    • GenericNvidiaPlatform acts as a catch-all for other NVIDIA accelerators.

    During resolution, launcher.py calls validate_host() for each host. This method logs warnings (e.g., if RDMA is missing on a DGX Spark node) but does not raise errors that stop the launch.

  6. Core concepts of sparkrun and OpenClaw integration

    main

    Understanding the following abstractions is key to managing workloads via OpenClaw:

    • Recipes: YAML files describing an inference workload (model, runtime, container, defaults). Recipe names can use @registry/name syntax for explicit registry selection.
    • Runtimes: Inference engines such as vLLM, SGLang, llama.cpp, or TensorRT-LLM.
    • Clusters: Named groups of DGX Spark hosts.
    • Registries: Git-based collections of recipes and benchmark profiles.
    • Benchmark profiles: Standardized benchmark configurations defined within registries.
    • Proxy: A unified OpenAI-compatible gateway that sits in front of multiple inference endpoints.
    • Tensor Parallelism (TP): Since each DGX Spark has 1 GPU, the --tp N flag maps directly to N hosts.
    • Detached Containers: sparkrun launches containers in a detached state. Using Ctrl+C will detach from logs but will not kill the running job.
  7. How the SSH Execution Model works

    main

    Remote operations in Sparkrun use SSH stdin piping. Instead of copying files to remote hosts, scripts are generated as Python strings and piped directly to the host via ssh host bash -s.

    from sparkrun.orchestration.ssh import run_remote_script
    result = run_remote_script(host, script_string, timeout=120, **ssh_kwargs)
  8. Understand the recipe YAML file format

    main

    Recipes are YAML files that define an inference workload for NVIDIA DGX Spark.

    Required Fields

    • model: HuggingFace model ID.
    • runtime: One of vllm, sglang, or llama-cpp.
    • container: The Docker image and tag (e.g., registry/image:tag).

    Key Configuration Sections

    • defaults: Defines parameters like port, host, tensor_parallel, pipeline_parallel, gpu_memory_utilization, and max_model_len. These are used for auto-generating commands and can be overridden via CLI.
    • command: An optional explicit command template. It supports {placeholder} syntax (e.g., {model}, {tensor_parallel}) which is substituted from defaults or CLI overrides.
    • env: Environment variables passed to the container. Supports shell variable expansion (e.g., ${HF_TOKEN}).
    • post_exec: Commands to run inside the head container after the server is healthy.
    • post_commands: Commands to run on the control machine after the server is healthy.

    Important Notes

    • GGUF + SGLang: When using GGUF models with the sglang runtime, you must set tokenizer_path in the defaults section, pointing to the base non-GGUF model.
    • Parallelism: pipeline_parallel enables pipeline parallelism. The total nodes required is calculated as TP * PP.
    model: org/model-name
    runtime: vllm
    container: registry/image:tag
    min_nodes: 1
    max_nodes: 4
    model_revision: abc123
    
    metadata:
      description: Human-readable description
      maintainer: name <email>
      model_params: 7B
      model_dtype: fp16
      category: general
    
    defaults:
      port: 8000
      host: 0.0.0.0
      tensor_parallel: 2
      pipeline_parallel: 1
      gpu_memory_utilization: 0.9
      max_model_len: 32768
      served_model_name: my-model
      tokenizer_path: org/base-model
    
    command: |
      python3 -m vllm.entrypoints.openai.api_server \
          --model {model} \
          --tensor-parallel-size {tensor_parallel} \
          --port {port}
    
    env:
      NCCL_DEBUG: INFO
    
    post_exec:
      - "echo 'Model loaded'"
    post_commands:
      - "curl http://{head_ip}:{port}/v1/models"
    stop_after_post: false
  9. How collective backends are selected

    main

    Collective backends manage the communication environment (like NCCL for NVIDIA) required for distributed inference.

    Backend selection follows these rules via orchestration/collectives/__init__.py:get_backend(vendor):

    • NVIDIA: If vendor is "nvidia" or None, NcclBackend() is used.
    • AMD: If vendor is "amd", RcclBackend() is used (currently a scaffold that raises NotImplementedError on environment generation).
    • Intel: If vendor is "intel", HcclBackend() is used (currently a scaffold that raises NotImplementedError on environment generation).
    • Other: Any other vendor results in an UnsupportedCollectiveError.

    core/backend_select.py:select_backends(host_hardware) automates this by deriving the vendor from the hardware and returning a BackendBundle containing the accelerator_vendor and the selected collective.

  10. Understand sparkrun core concepts

    main

    To effectively manage workloads with sparkrun, understand these key abstractions:

    • Recipes: YAML files that describe an inference workload, including the model, runtime, container, and default settings. Recipe names can use @registry/name syntax for explicit registry selection.
    • Runtimes: The inference engines supported, such as vLLM, SGLang, llama.cpp, and TensorRT-LLM.
    • Clusters: Named groups of NVIDIA DGX Spark hosts.
    • Registries: Git-based collections containing recipes and benchmark profiles.
    • Benchmark profiles: Standardized configurations for running benchmarks, sourced from registries.
    • Proxy: A unified, OpenAI-compatible gateway (based on LiteLLM) that sits in front of multiple inference endpoints.
    • Tensor Parallelism (TP): Since each DGX Spark has 1 GPU, the --tp N flag maps directly to the number of hosts (e.g., --tp 2 uses 2 hosts).
    • Detached Containers: sparkrun launches containers in a detached state. Using Ctrl+C will detach you from the logs but will not kill the running job.
  11. How the Executor abstraction works

    main

    Container engine operations are abstracted through the Executor ABC (orchestration/executor.py). Currently, DockerExecutor is the primary implementation. Runtimes should interact with the executor instance rather than importing Docker modules directly to maintain abstraction boundaries.

    # In a runtime:
    self.executor.run_cmd(image, command, container_name=name, env=env)
    self.executor.stop_cmd(container_name)
    self.executor.generate_launch_script(image, container_name, command, ...)
    self.executor.container_name(cluster_id, "solo")
    self.executor.node_container_name(cluster_id, rank)
  12. How OpenClaw uses sparkrun skills

    main

    OpenClaw automatically activates specific skills when your natural language request matches the task context. These skills allow OpenClaw to interact with the sparkrun CLI and the sparkrun_exec tool.

    SkillActivates When
    runRunning, monitoring, stopping, benchmarking, tuning, or managing inference workloads and proxy
    setupInstalling sparkrun, configuring clusters, SSH setup, CX7 networking, Docker group, permissions, earlyoom
    registryManaging recipe registries, browsing benchmark profiles, creating/editing recipes

    Usage Examples

    You can interact with your cluster using natural language commands such as:

    • "Run the Qwen3 1.7B model on my cluster"
    • "What inference jobs are running?"
    • "Stop all inference jobs on my cluster"
    • "Show me available recipes for llama models"
    • "Benchmark the sglang recipe on a single node"
    • "Set up sparkrun on my DGX Spark cluster"
    • "Configure CX7 networking on my cluster"
    • "Create a recipe for Mistral 7B on vLLM"
    • "Monitor my cluster's GPU usage"
    • "Start the inference proxy and load a model"