# load_projector API

> CLI and Python helpers in load_projector.py and modeling_projector.py.

---

LLMS index: [llms.txt](/Sage-SciPerception/llms.txt)

---

[`load_projector.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/load_projector.py) and [`modeling_projector.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/modeling_projector.py) live at the root of the repository and provide both a CLI downloader and Python loading helpers.

## CLI downloader {#cli}

```bash
python load_projector.py <projector_id> [--repo-id REPO_ID] [--revision REVISION] [--local-dir PATH]
```

| Argument / option | Default | Description |
|---|---|---|
| `projector_id` | — (required) | Component ID in `backbone/modality/task` form from the root HF `config.json` (e.g., `glm-5.3-flash/cif/jarvis`). |
| `--repo-id` | `internlm/Sage-SciPerception` | Hugging Face repository ID. |
| `--revision` | `main` | Branch, tag, or commit revision to resolve from. |
| `--local-dir` | `None` | Optional target directory where the root `config.json` and component files are materialized. |

The command prints the resolved local component directory path to stdout.

## Python functions (`load_projector.py`) {#python}

### `download_projector`

```python
download_projector(
    projector_id,
    repo_id="internlm/Sage-SciPerception",
    revision="main",
    local_dir=None,
    cache_dir=None,
) -> Path
```

Downloads the root `config.json` at `revision`, looks up `index["projectors"][projector_id]`, and pins the subsequent `config.json` and `weights` downloads to the exact resolved snapshot (`index_path.parent.name`). When `local_dir` is provided, the root `config.json` is also written under `local_dir`. Returns the component directory `Path`.

### `load_projector`

```python
load_projector(directory, device="cpu") -> tuple[nn.Module, dict]
```

Reads `config.json` from `directory`, instantiates the module with `modeling_projector.build(config["projector"], config["output_dim"])`, loads `config["weights"]` via `safetensors.torch.load_file(..., device="cpu")` with `strict=True`, moves the module to `device`, sets `.requires_grad_(False).eval()`, and returns `(model, config)`.

```python
from load_projector import download_projector, load_projector

component_dir = download_projector("glm-5.3-flash/cif/jarvis", local_dir="./checkpoints")
projector, config = load_projector(component_dir, device="cpu")
```

## Module helpers (`modeling_projector.py`) {#modeling}

| Helper | Description |
|---|---|
| `build(spec, output_dim, *, train_core=False, train_side_only=False) -> nn.Module` | Instantiates `AtomProjector`, `AtomSetProjector`, or `LeadProjector` from `config["projector"]` and attaches optional heads (`task_head`, `readout`, `side`, `graph`, `context`). |
| `load_initial(model, state)` | Loads an initial non-auxiliary core state dict into an `AtomProjector`, verifying that any optional prefix (`graph.`, `task_head.`, `side.`, `context.`, `readout.`) is either completely present or completely absent. |
