翻篇收录说明
翻篇网页快照

Serverless Training - Fireworks AI Docs

https://docs.fireworks.ai/fine-tuning/training-api/serverless

最近抓取:2026-12-03 17:06:51(北京时间)

最近内容变化:2026-12-03 17:06:51(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Fine-tune open models with your own Python training loop on shared Fireworks GPUs. Nothing to provision, and you pay per token.

正文摘录

Serverless training runs on shared Fireworks GPUs, so there is no trainer job or inference deployment to provision or delete. You can run supervised fine-tuning, preference optimization (DPO), reinforcement learning, distillation, or your own custom loop. Serverless supports LoRA training only. For full-parameter training or a model outside the serverless pool, use Dedicated Training. If you’re not sure, compare dedicated and serverless training or contact us. How it works 1 · LocalYour Python loopBuilds batches, rewards, and optimizer requests.2 · SharedTrainerRuns remote LoRA forward, backward, and optimizer work.3 · In sessionCheckpointCaptures the current adapter weights for sampling.4 · SharedSamplerReturns rollouts for local scoring and the next step. You write the training loop in Python. Fireworks runs the forward pass, backward pass, and optimizer step on shared GPUs, then serves your latest weights for sampling in the same session. For the terms used on this page, see the glossary. What you can run Supervised fine-tuning (SFT)Train on labeled examples with a cross-entropy loss.Reinforcement learning (RL)Sample, score with your own reward function, and train on the results.Direct preference optimization (DPO)Train from pairs of chosen and rejected responses.DistillationTrain a student model from a teacher model’s scores. Custom lossWrite your own loss function using the same Training API calls as dedicated training. Quickstart Requires Python 3.11 or later. Step 1: Create a key, install, and authenticate Create an API key in the Fireworks dashboard, or run firectl api-key create in your terminal. Then install the SDK and export the key: The example below runs from a source checkout. To import released recipes in your own project, use the PyPI installation. git clone https://github.com/fw-ai-external/cookbook pip install -e ./cookbook/training pip install math-verify # used by the DeepMath example to grade answers export FIREWORKS_API_KEY="fw_..." # the key you just created Step 2: Run the complete serverless RL example The cookbook’s DeepMath example includes its dataset, reward, training loop, and metrics. It trains on math problems with reinforcement learning (RL), using Group Relative Policy Optimization (GRPO). These flags keep the first run small: cd cookbook/training python -m examples.rl.deepmath.train_deepmath_serverless \ --base-model accounts/fireworks/models/muse-glimmer-30b \ --tokenizer-model meta-models/Muse-Glimmer-30B --renderer-name muse_glimmer \ --max-rows 32 --prompt-groups-per-step 8 --completions-per-prompt 4 \ --max-completion-tokens 4096 --max-seq-len 8192 --lora-rank 8 This is a real paid run. It first evaluates the base model, then trains, then evaluates again. Step 3: Clean up The run keeps one of your training slots until you delete its session. You can still list and promote its checkpoints after you delete the session, while the session/trainer records and checkpoint artifacts remain available, but promote the ones you want to keep soon after training. Training checkpoints stay loadable from a new run for about 30 days (see Checkpoint retention). Then delete the session, using the training session name the example printed (accounts/<ACCOUNT_ID>/trainingSessions/<SESSION_ID>): curl -X DELETE \ -H "Authorization: Bearer $FIREWORKS_API_KEY" \ https://api.fireworks.ai/v1/accounts/<ACCOUNT_ID>/trainingSessions/<SESSION_ID> To write your own loop instead of running the example, see Write your own training loop. Supported models Serverless supports these base models. For dedicated and managed options, see the Models catalog. On Kimi K3 and Kimi K3.1 Pro, a serverless LoRA trains the attention layers and the shared expert in each MoE layer. The routed experts and the router stay frozen. Pricing Serverless training is billed per token, across three meters: Prefill: prompt tokens the sampler reads. Repeated prefixes bill at the lower cached prefill rate. Sample: tokens the sampler generates. Train: tokens you train on (passed through forward_backward). Rates are USD per 1 million tokens. Available models and rates can change, so verify current availability in the Models catalog and the pricing page before launch. Base modelContextPrefillCached prefillSampleTrainMuse Spark Open256K$6.19$1.239$15.48$18.58DeepSeek V4.1 Flash 1017256K$0.60$0.12$3.60$4.98NVIDIA Nemotron 3.5 Super VL 120B256K$0.57$0.114$1.44$2.32GLM 5.3 Flash195K$2.96$0.593$7.41$8.89GLM 5.3256K$4.86$0.972$12.15$14.58Qwen 3.6 35B A3B256K$0.45$0.09$1.335$2.14Qwen 3.8 27B128K$1.86$0.372$5.595$4.103Kimi K3.1 Pro256K$2.40$0.24$12.00$25.00Kimi K3192K$10.87$2.17$27.11$32.55Muse Glimmer 30B128K$1.96$0.39$4.88$5.86 Nemotron 3.5 Super VL uses the current Tinker 256K card, which includes a limited-time 50% discount. Write your own training loop The DeepMath example wraps a loop you can write yourself with the SDK. To use the SDK without the cookbook, install it on its own: pip install "fireworks-ai[training]" Connect to a serverless session Run this Python script: import os from fireworks.training.sdk import FiretitanServiceClient service = FiretitanServiceClient( api_key=os.environ["FIREWORKS_API_KEY"], base_url="https://api.fireworks.ai/training/v1/serverless", ) base_model = "accounts/fireworks/models/qwen3p8-27b" max_seq_len = 131072 # enforce this when rendering prompts and training datums training_client = service.create_lora_training_client(base_model=base_model, rank=8) print(f"session={service.training_session_id} run={training_client.run_id}") If it prints a session ID that starts with ts-, your setup works. The session holds a training slot until you delete it. Train, checkpoint, and sample Each training step follows the order below. This excerpt doesn’t run on its own: it continues from the code above and uses datums, tokenizer, prompt, and params, which a complete loop such as the DeepMath example defines. from fireworks.training.sdk import AdamParams # One optimizer step training_client.forward_backward(datums, "importance_sampling").result() training_client.optim_step( AdamParams(learning_rate=2.5e-5, beta1=0.9, beta2=0.95, eps=1e-8, weight_decay=0.0) ).result() # Save weights and open a sampler bound to that exact snapshot snapshot = training_client.save_weights_for_sampler("step-0001").result().path sampler = service.create_sampling_client(model_path=snapshot, tokenizer=tokenizer) completions = sampler.sample( prompt=prompt, num_samples=8, sampling_params=params, ).result() sampler.close() Training and sampling calls return futures. Call .result() on each, or errors can go unnoticed. The tokenizer must match base_model. It formats prompts and decodes samples on your machine, so a mismatch silently corrupts your rewards. Give each checkpoint a different name. Saving twice with the same name points to the same snapshot. When you finish, close your clients and delete the session. For a complete RL loop, see the DeepMath example from the quickstart. For async scheduling and custom rollout functions, use the experimental async_rl_loop_serverless recipe. For other RL losses, see the cookbook RL recipes. Saving and loading checkpoints Serverless training writes two different kinds of checkpoint, and they are not interchangeable: Training checkpointSampler checkpointSaved bysave_state(name)save_weights_for_sampler(name)ContainsAdapter weights and optimizer stateCurrent adapter weights onlyResumable — the trainer can load it back and keep training✅ Yes❌ NoPromotable to a deployable model❌ No✅ Yes Only sampler checkpoints can be promoted to a final model, and only training checkpoints can be loaded back by the trainer to resume. A training checkpoint cannot be served or promoted. A sampler checkpoint cannot restore training state (weights + optimizer). Checkpoint storage is currently included at no charge. For the full SDK-level checkpoint reference (base/delta sampler types, weight sync, and cross-job resolution), see Dedicated Training and the Cookbook Reference. Save and resume training checkpoints Save training checkpoints periodically so an interrupted run can continue: # Save a training checkpoint (adapter weights + optimizer) for resume training_client.save_state("step-0100").result() # Resume inside the same run: restores weights and optimizer state training_client.load_state_with_optimizer("step-0100").result() # Weights-only load (optimizer resets to zero — a warm start) training_client.load_state("step-0100").result() Save and load calls return futures — call .result() to block and surface failures. save_state also accepts a timeout to bound the wait. Give each checkpoint a distinct name: overwriting an existing name (overwrite=True) is not supported. Keep checkpoint names to 17 characters or fewer. The server-side ID is run-<32-hex>-<your-name>-<8-hex> and must fit in 63 characters, leaving 17 for your name.This is only checked at promote time, so an overlong name fails after training completes. Recovery is load_state into a fresh session and re-saving under a shorter name. To see what checkpoints a run has saved, use the session-scoped control-plane list in Promote a sampler checkpoint to a model below — the trainer-local training_client.list_checkpoints() is not routed on the serverless surface. Resume a new run from a training checkpointTo fork a new run from a previous run’s training checkpoint, use create_training_client_from_state on the service client. The SDK reads the base model and LoRA configuration from the checkpoint itself, creates a fresh run, and loads the saved state:# Continue a previous run's training checkpoint in a new run (weights + optimizer) resumed_client = service.create_training_client_from_state_with_optimizer( "<account>/<run-id>/step-0100", ) # Or warm start from those weights with a fresh optimizer resumed_client = service.create_training_client_from_state( "<account>/<run-id>/step-0100", ) Checkpoint references are fully qualified as <account>/<run-id>/<checkpoint-name>, where run