fix(viewer): restart playback from earliest snapshot#846
Open
klei22 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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 ifexport_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 atry/finallysolive.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 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", | ||
| } |
Collaborator
Author
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


No description provided.