Skip to content

beam-thunder integration - #1814

Open
rohanphadnis-thunder wants to merge 28 commits into
beam-cloud:mainfrom
Thunder-Compute:main
Open

beam-thunder integration#1814
rohanphadnis-thunder wants to merge 28 commits into
beam-cloud:mainfrom
Thunder-Compute:main

Conversation

@rohanphadnis-thunder

@rohanphadnis-thunder rohanphadnis-thunder commented Jul 29, 2026

Copy link
Copy Markdown

Beam-Thunder Integration

This PR is for integrating beta9 with Thunder Compute. Key changes:

Phase 1: gpu_virtualized

gpu_virtualized, a boolean value is propagated from the Python beam client SDK to the beam gateway to each individual worker. Note that this is still a temporary change, preserved for its usefulness in prototyping. Eventually, GPU virtualization is controlled at the level of the pool. If a pool is virtualized, all its containers would be virtualized as well.

Phase 2: Beam Worker

The beam worker implements beta9/pkg/worker/thunder.go. This contains the ContainerThunderManager, a struct which implements the GPUManager interface. It mounts nvidia-smi, libcuda.so, and libnvidia-ml.so into the container from the host, but blocks the mounting of any physical GPU. For assigning and unassigning GPUs, it will use the gateway's thunder service and mint/revoke enrollment tokens as needed. Finally, when the container starts, the worker will run the curl installer in the container.

Phase 3: Beam Agent

The beam agent change is very easy.

  1. Tailscale is initialized on the host node. This was already the case. Thunder will simply need an IP address which is discoverable to all nodes and container clients in the pool. It will read the IP address of the tailscale0 interface.
  2. Next, the gateway will use newly added RPC call CreateNodeEnrollment to get a node enrollment token and run the node curl installer.
  3. Once the installer is run, the agent can continue its setup.

Phase 4: Beam Gateway

The beam gateway provides RPC calls to the beam agent and the beam worker in order to mint these enrollment tokens. It acts as a central client for the Thunder Compute API. This design ensures that the global API token isn't propagated to each beam agent/worker.

To make the Thunder information stateful, 3 new redis maps are added:

  1. for mapping client id to enrollment token id. This is so that when the client is unenrolled (ie during sandbox teardown), the thunder client's enrollment can be revoked.
  2. for mapping machine id to enrollment token id. This is so that if nodes ever need to be unregistered, the enrollment tokens for the nodes can be revoked.
  3. for mapping beam pools to thunder zone IDs. Each pool gets its own Thunder Zone ID.

Summary by cubic

Integrates Thunder Compute to enable virtualized GPU support via a new gpu_virtualized flag, with centralized Thunder enrollment across gateway, agent, and worker. This lets you schedule GPUs without exposing physical devices to containers.

  • New Features

    • Scheduling/API
      • Add gpu_virtualized to types.ContainerRequest and propagate through all abstractions and SDK; add scheduler helper to distinguish physical vs virtual GPUs.
    • Worker
      • Add ContainerThunderManager to mount nvidia-smi, libcuda.so.1, libnvidia-ml.so.1, and Thunder lib while blocking physical GPU devices when virtualized.
      • Request/revoke client enrollment via gateway ThunderService; wait for Thunder setup before exec and clean up on teardown.
    • Agent
      • Auto-enroll nodes with Thunder using tailscale0 IP via new gateway RPCs: CreateNodeEnrollment and DeleteNodeEnrollment; soft-fails if unavailable.
    • Gateway
      • Register ThunderService (pkg/gateway/services/thunder) with Redis-backed state and HTTP client; centralize THUNDER_API_TOKEN; mint/revoke client and node enrollment tokens; map pools to Thunder zones.
    • SDK
      • Add gpu_virtualized option to Pods, Sandboxes, and generic runners; forward to GetOrCreateStub.
    • Tooling
      • Add Thunder proto and generation in bin/gen_proto.sh.
  • Migration

    • Set THUNDER_API_URL and THUNDER_API_TOKEN in the gateway environment.
    • Ensure agents have Tailscale; node enrollment runs automatically.
    • Opt-in by setting gpu_virtualized=True in the beta9 Python SDK when launching Pods/Sandboxes/Functions.

Written for commit 9a6a9bb. Summary will update on new commits.

Review in cubic

@luke-lombardi luke-lombardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High level this looks good, mostly just some nit-picks around code organization

request := &types.ContainerRequest{
Cpu: i.StubConfig.Runtime.Cpu,
GpuCount: uint32(gpuCount),
GpuVirtualized: i.StubConfig.Runtime.GpuVirtualized,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still required? I know we talked about removing from the client, but I feel like it should also be removed from the container request as well.

Comment thread pkg/worker/lifecycle.go
}

func (s *Worker) deleteContainer(containerId string) {
s.thunderSetupTracker.Delete(containerId)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like the thundersetuptracker calls could be pushed down into the runtime layer potentially? feels like it could get confusing having those calls up here next to the core container lifecycle pieces

Comment thread pkg/worker/lifecycle.go
}()

exitCode, _ = s.runContainer(ctx, request, outputLogger, outputWriter, startedChan, checkpointPIDChan, opts.StartupStartedAt, opts.StartupPortBindings, opts.CheckpointFilesystemRestore)
exitCode, _ = s.runContainer(ctx, request, outputLogger, outputWriter, startedChan, checkpointPIDChan, thunderInstallResult, opts.StartupStartedAt, opts.StartupPortBindings, opts.CheckpointFilesystemRestore)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above, if theres a way to get this to be jammed into a runtime (under pkg/runtime) I think that would be cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants