Reproduce DGX Spark inference with request-local random state

Reproduce DGX Spark inference with request-local random state

Reproduce DGX Spark inference with request-local random state

Run the same prompt twice in a row and get different answers; pass a single-request test, then see results drift under concurrent load. These are separate problems: the first may be normal sampling behavior, while the second may reveal shared random state. Comparing answer text alone in a proof of concept can easily mistake scheduling differences for changes in model quality.

DGX Spark uses NVIDIA GB10 Grace Blackwell with an ARM64 architecture and runs NVIDIA DGX OS. Starting with an installed PyTorch environment that can execute CUDA operations, this article first checks random state against a fixed probability distribution, then applies the same checks to a real inference path. The experiment does not download a model or assume that packages are preinstalled.

1. Define the scope of reproducibility

Reproducibility has at least three levels: replaying the same request in the same environment, preserving each request’s sampling sequence when execution is interleaved, and obtaining identical results after software or hardware changes. This article tests the first two; it does not treat the third as a default guarantee.

Record the prompt’s original bytes, exact model and tokenizer revisions, chat template, generation parameters, and output token IDs. Readable text alone is not enough: different token sequences can decode to similar content, and whitespace handling can hide differences. Sampling parameters should also include temperature, truncation strategy, maximum generation length, and stopping conditions.

A fixed seed determines only the starting point of a random-number sequence. It does not fix model inputs, operator implementations, or the order in which random numbers are consumed. Exclusive use of an entire machine does not make numerical execution inherently deterministic, either.

First, stop other experimental processes and fix the request batch and execution path. If the production engine uses dynamic batching, record its batching policy separately. An offline single-request result is not, by itself, a promise of bitwise-identical results under concurrency.

2. Record the environment and enable diagnostic constraints

Save the following program as record_env.py and run it with the interpreter that actually performs inference. It checks CUDA availability, records software versions, and requires deterministic algorithms for supported operations.

import json
import platform
import torch

if not torch.cuda.is_available():
    raise SystemExit("CUDA is unavailable")

torch.use_deterministic_algorithms(True)
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.deterministic = True

record = {
    "machine": platform.machine(),
    "python": platform.python_version(),
    "torch": torch.__version__,
    "cuda_runtime": torch.version.cuda,
    "cudnn": torch.backends.cudnn.version(),
    "device": torch.cuda.get_device_name(0),
    "deterministic": torch.are_deterministic_algorithms_enabled()
}
print(json.dumps(record, ensure_ascii=False, indent=2))
umask 077
python3 record_env.py > environment.json
nvidia-smi > driver-report.txt
python3 -m pip freeze > packages.txt

These constraints apply only to the current Python process. Set them in the real inference entry point as well; running the recording script once does not change the entire system. Deterministic mode may reduce performance or cause some operations to raise errors. An error is evidence to investigate, not a reason to immediately switch to warnings and continue.

Some CUDA operations also require a workspace environment variable to be configured before the process starts. Follow the error messages and documentation for the installed version, and include the final settings in your records rather than copying parameters from another environment.

3. Create a separate generator for each request

First, leave model computation out of the test and check only the sampling chain. The fixed distribution below represents an unchanging probability vector over candidate tokens. The generator and probability tensor are on the same CUDA device to avoid confusing CPU and GPU random state.

import torch

torch.use_deterministic_algorithms(True)
device = torch.device("cuda:0")
probabilities = torch.tensor(
    [0.05, 0.15, 0.30, 0.50],
    device=device,
    dtype=torch.float32
)

def make_generator(seed):
    generator = torch.Generator(device=device)
    generator.manual_seed(seed)
    return generator

def draw(generator):
    return int(torch.multinomial(
        probabilities,
        num_samples=1,
        generator=generator
    ).item())

def sequence(seed, length=32):
    generator = make_generator(seed)
    return [draw(generator) for _ in range(length)]

assert sequence(31415) == sequence(31415)
print("same-request replay passed")

Save the program as sampling_check.py. Reusing a seed should produce exactly the same list, but the list does not need to match a particular set of numbers supplied by an article. The specific sequence belongs to the recorded software and device environment.

Different seeds do not guarantee different values at every position, nor do they rule out identical short sequences. “Changing the seed must change the answer” is therefore not a valid assertion. This test checks whether the same state can be replayed; it does not establish randomness quality from a small sample.

Connect the check to the real sampling path

An inference framework may not accept a generator parameter. Some interfaces accept only a request-level seed; others manage generators internally. Inspect the actual call chain in the current version and confirm that the setting reaches the final sampling operation, rather than merely creating an unused object outside it.

Do not reset the seed before every token, either. That repeatedly returns to the same starting point and changes the sampling semantics.

4. Expose state interference with interleaved execution

Append the following test to the same script. Run the two requests separately first, then alternate their sampling steps. Each request should retain its own sequence under both schedules.

expected_a = sequence(31415)
expected_b = sequence(27182)

generator_a = make_generator(31415)
generator_b = make_generator(27182)
actual_a = []
actual_b = []

for _ in range(32):
    actual_a.append(draw(generator_a))
    actual_b.append(draw(generator_b))

assert actual_a == expected_a
assert actual_b == expected_b
print("interleaved replay passed")

This is a controlled interleaving experiment, not a threaded stress test, but it can rule out the most common dependence on global state first. Next, send two overlapping requests through the actual service, compare their respective token IDs, and save request identifiers, seeds, batch configuration, and completion status.

As a negative test, temporarily make both requests share one generator and check whether the assertions fail. If the test always passes, verify that the test harness really interleaves execution, that the sequences are long enough, and that the results do not mistakenly reference the same object. The negative test demonstrates that the check can detect the problem; it should not become the production implementation.

5. Locate the first difference and archive the evidence

When repeating the checks with a real model, compare input token IDs first, then locate the first output divergence. If the inputs differ, investigate the template and tokenization. If the inputs match but the fixed-distribution test fails, investigate random state. If the fixed-distribution test passes but model outputs differ, examine operators, numerical precision, batching, and model state.

Before inference, call model.eval() to disable training-time behavior in the model, and use torch.inference_mode(). They serve different purposes: the latter does not automatically disable dropout. Even with greedy decoding, small floating-point differences between nearly tied candidates can change the entire subsequent output.

The final archive should contain at least the environment record, model revision, input tokens, generation parameters, request-level seeds, and output tokens. Exact replay of a custom sampler paused partway through also requires saving the generator state. Keeping only the initial seed does not skip the random numbers already consumed. Verify separately whether a continuous-batching engine supports this kind of recovery.

State the acceptance result as “Repeat and interleaving tests passed in the recorded environment with fixed inputs and execution path,” not “A fixed seed guarantees reproducibility forever.” Data is deleted when the DGX Spark usage term expires. Transfer experiment records and results elsewhere before expiration, and check that the files are readable at the destination, rather than leaving only screenshots of answers whose origins cannot be explained.

Frequently asked questions

Does a fixed seed guarantee identical model output?

No. Model and tokenizer revisions, sampling settings, random-state consumption, batching, and nondeterministic operations can all change output. Acceptance tests must target a documented, unchanged environment rather than promise bitwise equality across versions or hardware.

Should each concurrent request call global manual_seed?

Not as an isolation mechanism. Requests would modify shared state and could affect one another. When supported by the sampling interface, create a separate generator per request and explicitly pass it into the actual sampling operation.

AMD EPYC 7543P Dedicated Bare Metal Server

From $454/month

Configure a dedicated bare metal server for your workload

AMD EPYC 7543P servers are available with two memory options. The configuration page lists available add-ons and the amount due for the current billing period.