> ## Documentation Index
> Fetch the complete documentation index at: https://docs.m-star.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Implement nodes and walks

> Connect a model’s intake, GPU forwards, and outputs with graph edges.

Before loading weights, trace one example from input to output on paper. At each boundary, write down the tensor names, shapes, and which node consumes them. Those names become the graph’s edges.

## Build the walks

`get_graph_walk_graphs()` returns a mapping from walk names to graph sections. Use `GraphNode` for one submodule, `Sequential` or `Parallel` to compose nodes, and `Loop` for repeated work. If the same node name appears in several walks, those walks use the same submodule and its state.

In [Orpheus](https://github.com/mstar-project/mstar/blob/main/mstar/model/orpheus/orpheus_model.py), the LLM’s decode node has two outputs on each iteration. One edge routes the sampled token to the LLM as the next input. A streaming edge sends the token to the SNAC audio decoder. The decoder’s output targets `EMIT_TO_CLIENT` with `output_modality="audio"`. An ordinary `GraphEdge` describes a possible output. A forward may produce a subset, as BAGEL does when a prefill updates its cache without sampling text. [Graph primitives](https://github.com/mstar-project/mstar/blob/main/mstar/graph/base.py)

`walk_plan()` chooses the sequence for a particular request. Use a `WalkStep` with a binding when successive walks need different input spans. At ingest, a known output budget or denoising step count can set a named loop’s cap in `get_loop_caps()`. For a data-dependent end, such as a sampled EOS, the submodule reports completion in `check_stop`. [Model interface](https://github.com/mstar-project/mstar/blob/main/mstar/model/base.py) · [WalkStep](https://github.com/mstar-project/mstar/blob/main/mstar/conductor/request_info.py)

## Prepare a request

A model instance in the API process loads configuration and tokenizers. `process_prompt` validates the request, prepares tensors, and supplies the metadata used when scheduling. The weights for a node belong in `get_submodule`, called for the workers hosting it. Load just that node and reuse a constructed submodule if another walk needs it.

Keep small host values that are already known at ingest in metadata. Put audio, image tensors, embeddings, and other bulk data on named tensor edges. Declare accepted model-specific request settings in `request_kwargs()`. For sampling and output budgets, use the [shared request settings](https://docs.m-star.org/clients.md) and validate the model’s actual capabilities. Unknown keys are logged and ignored. Raise ValueError in process\_prompt or walk\_plan to refuse an invalid request with a 400.

For a new multimodal decoder, let the shared scaffold handle prompt intake. `DeclaredDecoderModel` chooses the walk for the available media encoders. The scaffold builds the `media_layout` metadata entry from PreparedMedia. It records the relationship between encoder rows and media pads in the prompt. Test two attachments separated by text so reversing the embeddings cannot pass unnoticed. [Scaffold](https://github.com/mstar-project/mstar/blob/main/mstar/model/multimodal_decoder.py) · [Prompt-order tests](https://github.com/mstar-project/mstar/blob/main/test/modular/test_qwen3_5_prompt_interleave.py)

## Run a node

| Hook | What it owns |
| - | - |
| `prepare_inputs` | Read a row’s incoming tensors and host metadata, set its input sequence length, and prepare model-specific inputs. |
| `declare_step` | Describe the ordered row segments, reads, writes, and samples for this step. The engine uses it for admission and planning. |
| `preprocess` | Arrange the selected batch into model input tensors. Keep their row order consistent with the step’s segments. |
| `forward` / `forward_batched` | Run tensor computation. Layers access state through handles bound by the engine. |
| `check_stop` | Inspect the outputs prepared for the host and report which loops finish. |
| `postprocess` | On the submodule, map forward results back to named outputs. On the `Model`, encode a request’s outgoing data in the format expected by the client. |

The worker can plan a later step while the current one is in flight. Calling `.item()` on a GPU tensor in preparation, or copying it to the CPU in a forward, introduces a synchronization there. A known loop count can avoid computing an extra speculative iteration. If a node cannot tolerate speculation, set `enable_async_scheduling=False` on its graph node. [Submodule signatures](https://github.com/mstar-project/mstar/blob/main/mstar/model/submodule_base.py) · [Async execution stages](https://github.com/mstar-project/mstar/blob/main/.claude/skills/async-worker/SKILL.md)

## Stream between partitions

Use a second partition when a consumer has its own walk schedule. Connect the producer’s streaming edge to a `Connection` with a chunk policy. The consumer’s buffer assembles each chunk. An audio codec that needs neighboring frames may read overlapping windows while emitting each frame once. Test a boundary in the middle of the stream and the final flush. [Orpheus example](https://docs.m-star.org/contributing/worked-examples.md#worked-example-orpheus) · [Stream buffer](https://github.com/mstar-project/mstar/blob/main/mstar/streaming/stream_buffer.py)

A connection from the CLIENT sentinel declares input from the caller. Implement process\_stream\_chunk to turn an append into tensor lists by edge name, or declare ClientAudio on every client stream to use the built-in decoder. A consumer that has already processed its last data can receive an empty final chunk. Its completion path must still finish the partition. [Client streaming interface](https://github.com/mstar-project/mstar/blob/main/mstar/model/base.py) · [Topology](https://github.com/mstar-project/mstar/blob/main/mstar/streaming/topology.py)

## Check a port

Exercise an intake error, one row, a mixed-length batch, and each output modality the model claims. Test graph declarations in dummy mode before loading a checkpoint. Test eager and captured forwards against the reference on real weights. A model serving an OpenAI route needs matching adapters for the [Rust frontend](https://github.com/mstar-project/mstar/blob/main/rust/server/src/adapters/mod.rs) and [Python frontend](https://github.com/mstar-project/mstar/blob/main/mstar/api_server/openai/adapters.py). Use the [adapter parity suite](https://github.com/mstar-project/mstar/blob/main/test/rust/test_rust_openai_adapters.py) for the routes you added.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.