Tinkex.API.Rest (Tinkex v0.3.4)

View Source

Low-level REST API endpoints for session and checkpoint management.

These functions provide direct access to the Tinker REST API endpoints. For higher-level operations, use Tinkex.RestClient.

Summary

Functions

Delete a checkpoint by training run and checkpoint ID.

Get the archive download URL for a checkpoint.

Get the archive download URL for a checkpoint by IDs.

Get sampler information.

Get session information.

Get training run information by ID.

Get training run information by tinker path.

Get checkpoint information from a tinker path.

List checkpoints for a specific training run.

List sessions with pagination.

List training runs with pagination.

List all checkpoints for the current user with pagination.

Publish a checkpoint to make it public.

Unpublish a checkpoint to make it private.

Functions

delete_checkpoint(config, checkpoint_path)

@spec delete_checkpoint(Tinkex.Config.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

Delete a checkpoint.

delete_checkpoint(config, run_id, checkpoint_id)

@spec delete_checkpoint(Tinkex.Config.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

Delete a checkpoint by training run and checkpoint ID.

get_checkpoint_archive_url(config, checkpoint_path)

@spec get_checkpoint_archive_url(Tinkex.Config.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

Get the archive download URL for a checkpoint.

The returned URL can be used to download the checkpoint archive.

get_checkpoint_archive_url(config, run_id, checkpoint_id)

@spec get_checkpoint_archive_url(Tinkex.Config.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

Get the archive download URL for a checkpoint by IDs.

The returned URL can be used to download the checkpoint archive.

get_sampler(config, sampler_id)

@spec get_sampler(Tinkex.Config.t(), String.t()) ::
  {:ok, Tinkex.Types.GetSamplerResponse.t()} | {:error, Tinkex.Error.t()}

Get sampler information.

Retrieves details about a sampler, including the base model and any custom weights that are loaded.

Parameters

  • config - The Tinkex configuration
  • sampler_id - The sampler ID (sampling_session_id) to query

Returns

  • {:ok, %GetSamplerResponse{}} - On success
  • {:error, Tinkex.Error.t()} - On failure

Examples

iex> {:ok, resp} = Rest.get_sampler(config, "session-id:sample:0")
iex> resp.base_model
"Qwen/Qwen2.5-7B"

See Also

get_session(config, session_id)

@spec get_session(Tinkex.Config.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

Get session information.

Returns training run IDs and sampler IDs associated with the session.

get_training_run(config, training_run_id)

@spec get_training_run(Tinkex.Config.t(), String.t()) ::
  {:ok, Tinkex.Types.TrainingRun.t()} | {:error, Tinkex.Error.t()}

Get training run information by ID.

Parameters

  • config - The Tinkex configuration
  • training_run_id - The training run ID

Returns

  • {:ok, map()} - Training run information on success
  • {:error, Tinkex.Error.t()} - On failure

get_training_run_by_tinker_path(config, tinker_path)

@spec get_training_run_by_tinker_path(Tinkex.Config.t(), String.t()) ::
  {:ok, Tinkex.Types.TrainingRun.t()} | {:error, Tinkex.Error.t()}

Get training run information by tinker path.

Parameters

  • config - The Tinkex configuration
  • tinker_path - The tinker path to the checkpoint

Returns

  • {:ok, map()} - Training run information on success
  • {:error, Tinkex.Error.t()} - On failure

get_weights_info_by_tinker_path(config, tinker_path)

@spec get_weights_info_by_tinker_path(Tinkex.Config.t(), String.t()) ::
  {:ok, Tinkex.Types.WeightsInfoResponse.t()} | {:error, Tinkex.Error.t()}

Get checkpoint information from a tinker path.

Retrieves metadata about a checkpoint, including the base model, whether it uses LoRA, and the LoRA rank.

Parameters

  • config - The Tinkex configuration
  • tinker_path - The tinker path to the checkpoint (e.g., "tinker://run-id/weights/checkpoint-001")

Returns

  • {:ok, %WeightsInfoResponse{}} - On success
  • {:error, Tinkex.Error.t()} - On failure

Examples

iex> path = "tinker://run-id/weights/checkpoint-001"
iex> {:ok, resp} = Rest.get_weights_info_by_tinker_path(config, path)
iex> resp.base_model
"Qwen/Qwen2.5-7B"
iex> resp.is_lora
true
iex> resp.lora_rank
32

Use Cases

Validating Checkpoint Compatibility

def validate_checkpoint(config, path, expected_rank) do
  case Rest.get_weights_info_by_tinker_path(config, path) do
    {:ok, %{is_lora: true, lora_rank: ^expected_rank}} ->
      :ok
    {:ok, %{is_lora: true, lora_rank: actual}} ->
      {:error, {:rank_mismatch, expected: expected_rank, actual: actual}}
    {:ok, %{is_lora: false}} ->
      {:error, :not_lora}
    {:error, _} = error ->
      error
  end
end

See Also

list_checkpoints(config, run_id)

@spec list_checkpoints(Tinkex.Config.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

List checkpoints for a specific training run.

list_sessions(config, limit \\ 20, offset \\ 0)

@spec list_sessions(Tinkex.Config.t(), integer(), integer()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

List sessions with pagination.

Options

  • :limit - Maximum number of sessions to return (default: 20)
  • :offset - Offset for pagination (default: 0)

list_training_runs(config, limit \\ 20, offset \\ 0)

@spec list_training_runs(Tinkex.Config.t(), integer(), integer()) ::
  {:ok, Tinkex.Types.TrainingRunsResponse.t()} | {:error, Tinkex.Error.t()}

List training runs with pagination.

Parameters

  • config - The Tinkex configuration
  • limit - Maximum number of training runs to return (default: 20)
  • offset - Offset for pagination (default: 0)

Returns

  • {:ok, map()} - List of training runs on success
  • {:error, Tinkex.Error.t()} - On failure

list_user_checkpoints(config, limit \\ 100, offset \\ 0)

@spec list_user_checkpoints(Tinkex.Config.t(), integer(), integer()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

List all checkpoints for the current user with pagination.

Options

  • :limit - Maximum number of checkpoints to return (default: 100)
  • :offset - Offset for pagination (default: 0)

publish_checkpoint(config, checkpoint_path)

@spec publish_checkpoint(Tinkex.Config.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

Publish a checkpoint to make it public.

unpublish_checkpoint(config, checkpoint_path)

@spec unpublish_checkpoint(Tinkex.Config.t(), String.t()) ::
  {:ok, map()} | {:error, Tinkex.Error.t()}

Unpublish a checkpoint to make it private.