RL

Forward-backward pass

Changed on

Submits a forward-backward pass operation that will asynchronously compute gradients via backpropagation.

post/v1/rl/training-sessions/{session_id}/operations/forward-backward

Request

  • Base URL
    https://api.together.ai
  • URL
    https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward
  • Auth
    HTTP bearer

Path parameters

session_idstring required

Training session ID

Headers

Idempotency-Keystring required

Required key that makes retries return the original operation; use a new key for changed request bodies.

Request body

return_loss_fn_outputsboolean

Return the loss function's per-sample output tensors alongside the loss and metrics. Defaults to false. Enabling it increases the response size substantially for large batches and reduces step throughput, so leave it unset for ordinary training steps.

forward_onlyboolean

Run the forward pass only: report the loss and metrics, and the per-sample outputs when requested, without accumulating gradients. Defaults to false. Pair it with return_loss_fn_outputs to score a batch and read back its per-token log-probabilities.

Example request

{
  "samples": [
    {
      "model_input": {
        "chunks": [
          {
            "encoded_text": {
              "tokens": [
                123,
                456,
                789
              ]
            }
          }
        ]
      }
    }
  ],
  "loss": {
    "grpo_params": {
      "clip_low_threshold": 0.8,
      "clip_high_threshold": 1.2,
      "beta": 0.1
    },
    "ppo_params": {
      "clip_low_threshold": 0.8,
      "clip_high_threshold": 1.2
    },
    "cispo_params": {
      "clip_high_threshold": 4
    },
    "dro_params": {
      "beta": 0.05
    },
    "dppo_params": {
      "delta_low": 0.15,
      "delta_high": 0.15
    }
  },
  "return_loss_fn_outputs": true,
  "forward_only": true
}

Response

idstring required

Operation ID

status'TRAINING_OPERATION_STATUS_UNSPECIFIED' | 'TRAINING_OPERATION_STATUS_PENDING' | 'TRAINING_OPERATION_STATUS_RUNNING' | 'TRAINING_OPERATION_STATUS_COMPLETED' | 'TRAINING_OPERATION_STATUS_FAILED' required

Example response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "output": {
    "loss": 2.345,
    "metrics": {
      "loss/clip/high_fraction": 0.1,
      "loss/kl_ref/mean": 0.05
    }
  },
  "error": {
    "message": "Operation timed out"
  }
}

Changes