# `HuggingfaceClient.Hub.AutoTrain`
[🔗](https://github.com/huggingface/huggingface_client/blob/v0.1.0/lib/huggingface_client/hub/compute/autotrain.ex#L1)

HuggingFace AutoTrain API — no-code/low-code model training.

AutoTrain allows training and fine-tuning ML models without writing training code.
Supports text classification, NER, Q&A, LLM fine-tuning, image classification, and more.

See: https://huggingface.co/docs/autotrain

## Supported Task Types

### NLP
- `"text-classification"` — sentiment, intent, topic classification
- `"token-classification"` — NER, POS tagging
- `"question-answering"` — extractive QA
- `"summarization"` — abstractive summarization
- `"translation"` — machine translation
- `"seq2seq"` — encoder-decoder tasks

### LLM
- `"llm-sft"` — supervised fine-tuning
- `"llm-orpo"` — ORPO alignment
- `"llm-dpo"` — DPO alignment
- `"llm-reward"` — reward modeling

### Vision
- `"image-classification"` — multi-class image classification
- `"image-regression"` — regression on images
- `"object-detection"` — bounding box detection

### Tabular
- `"tabular-classification"` — structured data classification
- `"tabular-regression"` — structured data regression

## Example

    # Create a text classification training job
    {:ok, project} = HuggingfaceClient.autotrain_create(
      project_name: "my-sentiment-model",
      task: "text-classification",
      base_model: "bert-base-uncased",
      dataset: "my-org/sentiment-dataset",
      column_mapping: %{"text" => "text", "label" => "label"},
      access_token: "hf_..."
    )

    # Check status
    {:ok, status} = HuggingfaceClient.autotrain_status(project["id"], access_token: "hf_...")
    IO.puts("Status: #{status["status"]}")

# `cancel`

```elixir
@spec cancel(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}
```

Cancels a running AutoTrain project.

## Example

    :ok = HuggingfaceClient.autotrain_cancel("my-project-id", access_token: "hf_...")

# `create`

```elixir
@spec create(keyword()) :: {:ok, map()} | {:error, Exception.t()}
```

Creates a new AutoTrain training project.

## Options

- `:project_name` — name for the project/output model (required)
- `:task` — task type string (required). See module docs for full list.
- `:base_model` — HF model ID to fine-tune from (required for LLM tasks)
- `:dataset` — HF dataset ID or dataset config
- `:column_mapping` — map of task columns to dataset columns
- `:hub_model` — output model destination (defaults to `user/project_name`)
- `:hardware` — compute flavor (e.g. `"a10g-small"`)
- `:params` — task-specific hyperparameters map
- `:namespace` — org/user namespace for billing
- `:access_token`

## Hyperparameter Examples

    # LLM fine-tuning params
    params: %{
      "epochs" => 3,
      "batch_size" => 2,
      "learning_rate" => 2.0e-4,
      "max_seq_length" => 2048,
      "lora_r" => 16,
      "lora_alpha" => 32,
      "use_peft" => true
    }

    # Text classification params
    params: %{
      "epochs" => 5,
      "batch_size" => 16,
      "learning_rate" => 3.0e-5,
      "max_seq_length" => 512
    }

# `delete`

```elixir
@spec delete(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}
```

Deletes an AutoTrain project.

## Example

    :ok = HuggingfaceClient.autotrain_delete("my-project-id", access_token: "hf_...")

# `get_logs`

```elixir
@spec get_logs(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, Exception.t()}
```

Gets training logs for a project.

# `get_metrics`

```elixir
@spec get_metrics(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Gets training metrics (loss, accuracy, etc.) for a project.

# `list`

```elixir
@spec list(keyword()) :: {:ok, [map()]} | {:error, Exception.t()}
```

Lists all AutoTrain projects for the authenticated user or namespace.

## Example

    {:ok, projects} = HuggingfaceClient.autotrain_list(access_token: "hf_...")
    Enum.each(projects, fn p ->
      IO.puts("#{p["name"]}: #{p["status"]}")
    end)

# `list_hardware`

```elixir
@spec list_hardware(keyword()) :: {:ok, [map()]} | {:error, Exception.t()}
```

Returns available hardware options for AutoTrain.

# `list_tasks`

```elixir
@spec list_tasks(keyword()) :: {:ok, [map()]} | {:error, Exception.t()}
```

Returns available task types and their descriptions.

## Example

    {:ok, tasks} = HuggingfaceClient.autotrain_list_tasks()
    Enum.each(tasks, fn t -> IO.puts("#{t["name"]}: #{t["description"]}") end)

# `status`

```elixir
@spec status(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Gets the status of an AutoTrain project.

## Example

    {:ok, project} = HuggingfaceClient.autotrain_status("my-project-id",
      access_token: "hf_..."
    )
    IO.puts("Status: #{project["status"]}")
    IO.puts("Model: #{project["output_model"]}")

---

*Consult [api-reference.md](api-reference.md) for complete listing*
