Skip to main content
Flash passes a managed client to your main(client) function. An async entrypoint receives awaitable methods; a synchronous entrypoint uses blocking methods with the same arguments. Start with Custom algorithms. Install freesolo-flash[custom] for local PyTorch losses.

State and sequencing

Operations are serialized within a session. Several backward calls can accumulate gradients, but async calls do not create simultaneous optimizer updates. Await an operation’s result before using it. Cancellation of a local await does not prove that the remote mutation was cancelled.

Token data

Position zero predicts token 20 from token 10; position one predicts token 30 from the first two tokens. Each row has at least two token IDs and at most train.max_context_tokens. Weights have len(tokens) - 1 entries. Set weights for prompt targets to zero. There is no automatic averaging: divide by the number of tokens, examples, or other denominator your objective requires. With target_tokens, supply a rectangular [len(tokens)-1, K] matrix where K is 1–64. Weights and returned scores have that same shape. See soft targets.

Operations

load_checkpoint is not supported for managed sessions. Start a new run with custom.resume_from to restore a durable step, or train.init_from_adapter for a fresh optimizer initialized from an adapter. A custom loss has the signature loss_fn(data, logprobs) and returns (scalar_tensor, metrics). Each tensor has shape [T], or [T, K] for explicit targets, and supports local autograd. Return a finite scalar and finite numeric metrics. Cross-sequence losses can compare multiple rows; do not detach the scores or convert the loss to a Python float before returning it.

Request limits

These protocol limits are separate from memory admission. Full-vocabulary logits can exhaust GPU memory even with a small number of target candidates. Reduce sequence length or row size when an operation exceeds available memory. The configuration reference specifies run-level limits and the release dependency for larger custom shapes.

Failure and resume

If an operation’s outcome is unresolved, use retry_pending() rather than reissuing it as a new update. Do not replay a mutation into a different session. A failed session requires a new run from a durable checkpoint. Pass your cursor/state to optim_step(algorithm_state=...) so automatic saves include it, then resume from client.step and client.restored_state. Finishing the Python function does not add optimizer steps automatically. Keep the controller running until your intended horizon is reached; Ctrl-C cancels a custom run. See durable resume.