Skip to content

fix(viewer): restart playback from earliest snapshot#846

Open
klei22 wants to merge 2 commits into
ReaLLMASIC:masterfrom
klei22:add-min-angle-graph
Open

fix(viewer): restart playback from earliest snapshot#846
klei22 wants to merge 2 commits into
ReaLLMASIC:masterfrom
klei22:add-min-angle-graph

Conversation

@klei22

@klei22 klei22 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds an optional validation-time export of the LM-head minimum-angle nearest-neighbor graph (CSV + JSON sidecar) and provides a local Plotly-based HTML viewer to step through exported snapshots over training.

Changes:

  • Add blockwise minimum-angle graph computation + CSV/JSON export utility and wire it into train.py (optional per-eval export via new CLI args).
  • Document the export workflow and add an experiment config + demo script for smoke-testing.
  • Add a standalone Plotly HTML viewer that loads exported CSVs, sorts snapshots by iteration, and supports stepping/playback.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
utils/min_angle_graph_export.py Implements blockwise minimum-angle graph computation and CSV/JSON export helpers.
train.py Adds optional per-validation export hook and a stdlib-shadowing guard at startup.
train_args.py Introduces CLI flags to configure and enable exports.
README.md Documents how to enable exports and use the Plotly viewer.
explorations/min_angle_graph_export.yaml Adds a smoke-test experiment configuration for the export feature.
demos/min_angle_graph_export_demo.sh Adds a demo script to run the smoke-test and point users to the viewer.
analysis/min_angle_graph_plotly_viewer.html Adds a local viewer for exploring exported CSV snapshots over time.
Comments suppressed due to low confidence (1)

train.py:1932

  • The export runs between live.stop() / live.start(), but if export_min_angle_graph() throws (OOM, IO error, etc.) the Rich Live UI will never be restarted, leaving the terminal in a broken state. Wrap the export in a try/finally so live.start() always runs.
                better_than_chance = self._safe_better_than_chance(self.vocab_sizes[dataset], dataset_losses['val'].item())
                self.log_metrics(dataset_losses, running_mfu, current_epoch, self.tokens_trained, dataset, better_than_chance)
        else:
            better_than_chance = self._safe_better_than_chance(self.model_args['vocab_size'], losses['val'].item())
            log_message=f"step {self.iter_num}:"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +358 to +368
rowsBody.innerHTML = currentRowsForTable(snapshot).map((row) => `
<tr>
<td>${row.min_angle_rank}</td>
<td>${row.token_id}</td>
<td>${row.nearest_token_id}</td>
<td>${Number(row.min_angle_deg).toFixed(6)}</td>
<td>${Number(row.cosine).toFixed(6)}</td>
<td>${Number(row.token_vector_length).toFixed(6)}</td>
<td>${Number(row.nearest_token_vector_length).toFixed(6)}</td>
</tr>
`).join("");
Comment thread README.md
Comment on lines +264 to +269
LM-head angle explorer's minimum-angular-distance view after each validation
loss. The export treats each LM-head row as a token vector, streams
row/column blocks through the selected compute device, excludes each token's
self-distance, and records the closest non-self token by signed `0°–180°`
angular distance. The full `vocab_size × vocab_size` angle matrix is never
materialized.
Comment on lines +24 to +26
def compute_min_angle_graph(weight, block_size=2048, compute_device="auto"):
"""Compute each row vector's closest non-self row by signed angular distance."""
compute_device = resolve_min_angle_graph_device(weight, compute_device)
Comment on lines +133 to +142
metadata = {
"iter_num": iter_num,
"val_loss": val_loss,
"label": label,
"csv_path": csv_path,
"vocab_size": vocab_size,
"block_size": graph["block_size"],
"compute_device": graph["compute_device"],
"angle_definition": "signed 0-180 degrees, closest non-self token by maximum cosine",
}
@klei22

klei22 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author
image

@klei22

klei22 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants