Skip to content

Commit 8246b7c

Browse files
committed
[Doc] V1 of docs with gh pages workflow
Ref #6
1 parent 39f2560 commit 8246b7c

21 files changed

Lines changed: 976 additions & 284 deletions

.github/workflows/docs-release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Deploy Release Docs to GitHub Pages
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: write
9+
pages: write
10+
id-token: write
11+
12+
concurrency:
13+
group: "pages"
14+
fail-fast: false
15+
16+
jobs:
17+
deploy:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event.release.tag_name }}
23+
fetch-depth: 0
24+
25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.11"
28+
29+
- name: Install dependencies
30+
run: |
31+
pip install -e .
32+
pip install -e xlm-models/
33+
pip install -e xlm-models/idlm/
34+
pip install mkdocs mkdocs-material "mkdocstrings[python]" mike
35+
36+
- name: Extract version from tag
37+
id: get_version
38+
run: |
39+
TAG_NAME="${{ github.event.release.tag_name }}"
40+
VERSION=${TAG_NAME#v}
41+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
42+
if [[ $PATCH == *"-"* ]]; then
43+
PATCH_NUM=$(echo $PATCH | cut -d'-' -f1)
44+
else
45+
PATCH_NUM=$PATCH
46+
fi
47+
echo "version=${MAJOR}.${MINOR}" >> $GITHUB_OUTPUT
48+
echo "Version: ${MAJOR}.${MINOR}"
49+
50+
- name: Configure git
51+
run: |
52+
git config user.name "github-actions[bot]"
53+
git config user.email "github-actions[bot]@users.noreply.github.com"
54+
55+
- name: Fetch gh-pages
56+
run: git fetch origin gh-pages --depth=1 || true
57+
58+
- name: Deploy release docs to gh-pages
59+
run: mike deploy ${{ steps.get_version.outputs.version }} --update-aliases latest --push
60+
61+
- name: Set default version
62+
run: mike set-default latest --push

.github/workflows/docs.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy Docs to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
fail-fast: false
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.11"
28+
29+
- name: Install dependencies
30+
run: |
31+
pip install -e .
32+
pip install -e xlm-models/
33+
pip install mkdocs mkdocs-material "mkdocstrings[python]" mike
34+
35+
- name: Configure git
36+
run: |
37+
git config user.name "github-actions[bot]"
38+
git config user.email "github-actions[bot]@users.noreply.github.com"
39+
40+
- name: Fetch gh-pages
41+
run: git fetch origin gh-pages --depth=1 || true
42+
43+
- name: Deploy docs to gh-pages
44+
run: mike deploy dev --push
45+
46+
- name: Set default version (when no releases exist)
47+
run: |
48+
if ! mike list latest 2>/dev/null; then
49+
mike set-default dev --push
50+
fi

.gitignore

Lines changed: 6 additions & 282 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<img src="./assets/xlm.gif" width="180" alt="XLM Logo"/>
2+
<img src="./docs/xLM_bold.png" width="180" alt="XLM Logo"/>
33
</p>
44

5-
<h1 align="center">XLM</h1>
5+
<!-- <h1 align="center">XLM</h1> -->
66

77
<p align="center">
88
<strong>A Unified Framework for Non-Autoregressive Language Models</strong>

docs/guide/building-docs.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Building Docs
2+
3+
This page describes how the XLM documentation is built and deployed.
4+
5+
## Local Build
6+
7+
Install dependencies and build the docs:
8+
9+
```bash
10+
pip install -e .
11+
pip install -e xlm-models/
12+
pip install -r requirements/docs_requirements.txt
13+
mkdocs build
14+
```
15+
16+
## Local Serve
17+
18+
To preview the docs with live reload:
19+
20+
```bash
21+
mkdocs serve
22+
```
23+
24+
Open http://127.0.0.1:8000 in your browser.
25+
26+
## Versioning
27+
28+
The docs use [mike](https://github.com/jimporter/mike) for multi-version deployment:
29+
30+
| Version | URL path | Description |
31+
|---------|-----------|--------------------------------|
32+
| `dev` | `/dev/` | Development build (main branch)|
33+
| `latest`| `/latest/`| Newest release (alias) |
34+
| `1.4` | `/1.4/` | Release v1.4.0 |
35+
36+
- **dev** – Always tracks `main`; deployed on every push to main.
37+
- **latest** – Points to the most recent release; updated when a new release is published.
38+
- **Versioned releases** – Each release (e.g., v1.4.0) is deployed to its `major.minor` path (e.g., `/1.4/`).
39+
40+
To preview all deployed versions locally (requires the `gh-pages` branch):
41+
42+
```bash
43+
mike serve
44+
```
45+
46+
To deploy a version manually:
47+
48+
```bash
49+
mike deploy <version> [alias]...
50+
```
51+
52+
For example: `mike deploy dev` or `mike deploy 1.4 latest --update-aliases`.
53+
54+
## Structure
55+
56+
The docs use:
57+
58+
- **MkDocs** – Static site generator
59+
- **Material theme** – Navigation tabs, sections, integrated TOC, and version selector
60+
- **mkdocstrings** – API reference generated from Python docstrings
61+
- **mike** – Versioning and multi-version deployment
62+
63+
## CI Deployment
64+
65+
### Main branch (dev)
66+
67+
The [.github/workflows/docs.yml](https://github.com/dhruvdcoder/xlm-core/blob/main/.github/workflows/docs.yml) workflow:
68+
69+
1. Triggers on push to `main` or manual `workflow_dispatch`
70+
2. Installs xlm-core, xlm-models, and idlm
71+
3. Installs MkDocs, Material, mkdocstrings, and mike
72+
4. Runs `mike deploy dev --push` to deploy to the `/dev/` path on the `gh-pages` branch
73+
74+
### Releases (versioned + latest)
75+
76+
The [.github/workflows/docs-release.yml](https://github.com/dhruvdcoder/xlm-core/blob/main/.github/workflows/docs-release.yml) workflow:
77+
78+
1. Triggers when a GitHub release is published
79+
2. Checks out the release tag
80+
3. Extracts the version (e.g., `v1.4.0``1.4`)
81+
4. Runs `mike deploy 1.4 --update-aliases latest --push`
82+
5. Runs `mike set-default latest --push` so the site root redirects to the latest release
83+
84+
**Prerequisite**: Enable GitHub Pages in repo Settings → Pages → Source: "Deploy from a branch" → Branch: `gh-pages` / `/(root)`.
85+
86+
## Dependencies
87+
88+
Install docs dependencies from `requirements/docs_requirements.txt`:
89+
90+
```
91+
mkdocs>=1.6
92+
mkdocs-material>=9.0
93+
mkdocstrings[python]>=0.24
94+
mike>=2.0
95+
```

docs/guide/contributing.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Adding a new language model architecture to XLM
2+
3+
For scaffolding a new external model, see [External Models](external-models.md). This document outlines the process for adding a new language model architecture to the XLM codebase. The code follows a modular design with four main components that work together to provide a complete language modeling solution. You need to implement all of them in order to add a new working model.
4+
5+
## Overview of Main Components
6+
7+
### 1. **LossFunction**
8+
The `LossFunction` is responsible for computing the training loss during model training, validation and optionally test time.
9+
10+
**Key Responsibilities:**
11+
- Compute loss between model predictions and ground truth targets
12+
- Return a dictionary with "loss" key and any other additional values that you want to track.
13+
14+
**Interface:**
15+
```python
16+
class LossFunction(Generic[T_in, T_out], Protocol):
17+
model: Any
18+
tokenizer: Tokenizer
19+
20+
def loss_fn(self, batch: T_in, ...) -> T_out: ...
21+
def configure(self, pl_module: "Harness"): ...
22+
"""Converts scalar to tensor such that loss_fn becomes compile friendly. If you don't want to compile you don't need to implement this.
23+
"""
24+
```
25+
26+
Examples: `xlm-models/arlm/loss_arlm.py`
27+
28+
### 2. **Predictor**
29+
The `Predictor` handles generating output sequences from the model.
30+
31+
**Key Responsibilities:**
32+
- Run the model (typically in a loop) to produce a sequence of tokens.
33+
- Convert generated token_ids to text.
34+
35+
**Interface:**
36+
```python
37+
class Predictor(Generic[T_in, T_out_pred], Protocol):
38+
tokenizer: Tokenizer
39+
noise_schedule: NoiseSchedule
40+
model: Any
41+
42+
def predict(self, batch: T_in, ...) -> T_out_pred: ...
43+
def to_dict(self, batch: T_in, preds: T_out_pred, ...) -> List[Dict[str, Any]]: ...
44+
```
45+
46+
Examples: `xlm-models/arlm/predictor_arlm.py`
47+
48+
### 3. **Collator**
49+
The `Collator` prepares batches of data for training and inference. It handles data preprocessing, padding, and batching.
50+
51+
**Key Responsibilities:**
52+
- It receives raw token_ids and converts them to a dict which is passed in as a batch to the model.
53+
- Handle padding and truncation.
54+
55+
**Interface:**
56+
```python
57+
class Collator(Protocol):
58+
"""For pre-training the model on language modeling."""
59+
def __call__(self, examples: List[Dict[str, Any]]) -> Dict[str, Any]: ...
60+
61+
class Seq2SeqCollator(Collator):
62+
"""For training the model on seq2seq tasks."""
63+
def __call__(self, examples: List[Dict[str, Any]]) -> Dict[str, Any]: ...
64+
65+
class Seq2SeqCollatorPrediction(Collator):
66+
"""For generating predictions for seq2seq tasks."""
67+
def __call__(self, examples: List[Dict[str, Any]]) -> Dict[str, Any]: ...
68+
```
69+
70+
Examples: `xlm-models/arlm/datamodule_arlm.py`
71+
72+
### 4. **Model**
73+
The `Model` is the bare neural network architecture for your LM. It defines the forward pass and model parameters.
74+
75+
**Key Responsibilities:**
76+
- Define the neural network architecture.
77+
- Implement the forward pass.
78+
79+
**Interface:**
80+
```python
81+
class Model:
82+
def forward(self, input_ids: Tensor, attention_mask: Optional[Tensor] = None, ...) -> Tensor: ...
83+
```
84+
85+
Examples: `xlm-models/arlm/model_arlm.py`
86+
87+
All these four components are designed to be aware of each other, and are only expected to run with each other for the same LM and not with any other LM. This is a key design choice that allows one to implement really esoteric models without worrying about how to abstract them such that their dataflow becomes compatible with other LMs.
88+
89+
## Step-by-Step Guide
90+
91+
See the [External Models](external-models.md) guide for the recommended workflow using `xlm-scaffold`. The scaffold creates the directory structure, type definitions, and config stubs. You then implement the four components (Model, Loss, Predictor, Collator) and register them in Hydra configuration.
92+
93+
Key config locations (paths may vary for external models in `xlm-models/`):
94+
95+
- `configs/lightning_train/collator/` – Collator configs
96+
- `configs/lightning_train/datamodule/` – Datamodule configs
97+
- `configs/lightning_train/model/` – Model (neural network) configs
98+
- `configs/lightning_train/model_type/` – Loss, predictor, metrics
99+
- `configs/lightning_train/experiment/` – Experiment configs
100+
101+
## Design
102+
103+
### Why is there so much nesting in the datamodule config?
104+
105+
The main component of the datamodule are the `dataset_managers`. Each `dataset_manager` will generate its own `dataloader` with its own `collator` and processing functions. This design allows:
106+
107+
1. Chaining arbitrary number of "eval" tasks/datasets during validation or testing
108+
2. Injecting new eval tasks post-training
109+
110+
## Best Practices
111+
112+
- **Type Safety**: Use `jaxtyping` for tensor type annotations; define clear interfaces with `TypedDict` and `Protocol`
113+
- **Modularity**: Keep components loosely coupled; use dependency injection through configuration
114+
- **Testing**: Use debug mode configs (`debug=overfit`, `debug=small_data`) for quick testing
115+
- **Documentation**: Document all public interfaces; include examples in docstrings
116+
117+
## Troubleshooting
118+
119+
1. **Hydra Errors**: If you see `Unable to find or instantiate abc.xyz.MyClass`, try importing manually: `python -c "from abc.xyz import MyClass"`.
120+
2. **Unable to implement a component**: Check existing models in `xlm-models/` (arlm, mlm, ilm, mdlm) for reference.

0 commit comments

Comments
 (0)