Spaces:
Sleeping
Sleeping
Commit Β·
e248349
1
Parent(s): 1356785
Fixed single-token sequence UI bug
Browse files- .agents/rules/agent-workflow.md +61 -0
- app.py +44 -3
- plans.md +2 -0
.agents/rules/agent-workflow.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
trigger: always_on
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
# Transformer Explanation Dashboard
|
| 6 |
+
Interactive Dash app for exploring LLM internals through visualization and experimentation. Built with Python, Dash, PyTorch, HF Transformers, Bertviz, pyvene.
|
| 7 |
+
|
| 8 |
+
## Critical Rules
|
| 9 |
+
- **Dead code cleanup is mandatory during refactors.** Sweep for orphaned code from deprecated/deleted components every time.
|
| 10 |
+
- **Conceptual understanding over math rigor.** Skip complex derivations; focus on motivation and intuition that builds correct mental models.
|
| 11 |
+
- **Sanity check every change:** (1) Does this help someone learn about transformers? (2) Is the simplification accurate enough? (3) Am I in a rabbit hole?
|
| 12 |
+
- **TDD for backend logic.** Write failing tests first for anything in `utils/`. Skip tests for UI-only changes. Run `pytest` after every change; iterate until green.
|
| 13 |
+
- **Don't run the app.** Describe manual verification steps; the user will test themselves.
|
| 14 |
+
- **Surgical edits over rewrites.** Reuse existing files. Only create new modules when existing ones can't be extended.
|
| 15 |
+
- **No new dependencies** unless strictly necessary.
|
| 16 |
+
- **Push back on bad ideas.** Think through problems fully. Don't be a yes-man β challenge flawed approaches.
|
| 17 |
+
- **Components = layout only** (no ML logic). **Utils = computation only** (no Dash imports). **app.py = glue.**
|
| 18 |
+
- **Dash callbacks must stay responsive.** No heavy sync work in callbacks without feedback indicators.
|
| 19 |
+
- Don't reformat unrelated code or alter indentation styles.
|
| 20 |
+
- Check for zombie processes before debugging server errors.
|
| 21 |
+
|
| 22 |
+
## Module Map
|
| 23 |
+
| Module | Path | Load when |
|
| 24 |
+
|--------|------|-----------|
|
| 25 |
+
| Product | `.context/modules/product.md` | Understanding vision, features, brand voice, visual identity, UX patterns |
|
| 26 |
+
| Architecture | `.context/modules/architecture.md` | Understanding system structure, data flow, or component boundaries |
|
| 27 |
+
| Conventions | `.context/modules/conventions.md` | Writing or reviewing code style, naming, commits, dead code cleanup |
|
| 28 |
+
| Education | `.context/modules/education.md` | Creating or editing educational content, visualizations, explanations |
|
| 29 |
+
| Testing | `.context/modules/testing.md` | Writing tests, running pytest, TDD workflow |
|
| 30 |
+
|
| 31 |
+
## Data Files
|
| 32 |
+
| File | Path | Purpose |
|
| 33 |
+
|------|------|---------|
|
| 34 |
+
| Sessions | `.context/data/sessions.md` | Running work log (append-only) |
|
| 35 |
+
| Decisions | `.context/data/decisions.md` | Decision records with reasoning (append-only) |
|
| 36 |
+
| Lessons | `.context/data/lessons.md` | Hard-won knowledge and past mistakes (append-only) |
|
| 37 |
+
|
| 38 |
+
## Memory Maintenance
|
| 39 |
+
|
| 40 |
+
Always look for opportunities to update the memory system:
|
| 41 |
+
- **New patterns**: "We've been doing X consistently β should I add it to conventions?"
|
| 42 |
+
- **Decisions made**: "We decided Y β should I record this in decisions.md?"
|
| 43 |
+
- **Mistakes caught**: "This went wrong because Z β should I add it to lessons.md?"
|
| 44 |
+
- **Scope changes**: "The project now includes W β should I create a new module?"
|
| 45 |
+
|
| 46 |
+
**Before any memory update**:
|
| 47 |
+
1. State which file(s) would change and what the change would be
|
| 48 |
+
2. Wait for approval
|
| 49 |
+
3. Never update memory mid-task without mentioning it
|
| 50 |
+
|
| 51 |
+
**Rules**:
|
| 52 |
+
- Data files are append-only β add entries, never remove or overwrite past entries
|
| 53 |
+
- Modules can be edited but changes should be targeted, not full rewrites
|
| 54 |
+
- After substantive work sessions, append a summary to `.context/data/sessions.md`
|
| 55 |
+
|
| 56 |
+
## Preferences
|
| 57 |
+
- Don't ask permission for changes that fall within an approved plan β just execute
|
| 58 |
+
- Commit normal changes to main; feature branches for major components/refactors. Never merge branches.
|
| 59 |
+
- Keep `todo.md` and `plans.md` current before/after changes. Tasks should be atomic.
|
| 60 |
+
- When in doubt, research options and make a minimal reasonable choice, noting it in `todo.md`
|
| 61 |
+
- Explain manual tests clearly β what to look for, expected behavior, where to check
|
app.py
CHANGED
|
@@ -432,9 +432,50 @@ def run_generation(n_clicks, model_name, prompt, max_new_tokens, beam_width, pat
|
|
| 432 |
activation_data, activation_data, original_prompt_data, {})
|
| 433 |
|
| 434 |
else:
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
activation_data, activation_data, original_prompt_data, selected_beam_data)
|
| 439 |
|
| 440 |
except Exception as e:
|
|
|
|
| 432 |
activation_data, activation_data, original_prompt_data, {})
|
| 433 |
|
| 434 |
else:
|
| 435 |
+
if beam_width > 1:
|
| 436 |
+
# Multiple beams, single token β show selection UI
|
| 437 |
+
results_ui.append(html.H4("Generated Sequences", className="section-title"))
|
| 438 |
+
results_ui.append(html.P("Select a sequence to store for comparison after experiments.",
|
| 439 |
+
style={'color': '#6c757d', 'fontSize': '13px', 'marginBottom': '12px'}))
|
| 440 |
+
for i, result in enumerate(results):
|
| 441 |
+
results_ui.append(html.Div([
|
| 442 |
+
html.Div([
|
| 443 |
+
html.Span(f"Rank {i+1}", style={'fontWeight': 'bold', 'marginRight': '10px', 'color': '#667eea'})
|
| 444 |
+
], style={'marginBottom': '5px'}),
|
| 445 |
+
html.Div(result['text'], style={'fontFamily': 'monospace', 'backgroundColor': '#fff', 'padding': '10px', 'borderRadius': '4px', 'border': '1px solid #dee2e6'}),
|
| 446 |
+
html.Button("Select for Comparison", id={'type': 'result-item', 'index': i}, n_clicks=0,
|
| 447 |
+
className="action-button secondary-button", style={'marginTop': '10px', 'fontSize': '12px'})
|
| 448 |
+
], style={'marginBottom': '15px', 'padding': '15px', 'backgroundColor': '#f8f9fa', 'borderRadius': '6px'}))
|
| 449 |
+
selected_beam_data = {}
|
| 450 |
+
else:
|
| 451 |
+
# Single beam, single token β auto-select and show "Selected" badge
|
| 452 |
+
result = results[0]
|
| 453 |
+
selected_beam_data = {'text': result['text'], 'score': result.get('score', 0)}
|
| 454 |
+
results_ui.append(html.Div([
|
| 455 |
+
html.H4("Selected Sequence", className="section-title"),
|
| 456 |
+
html.Div([
|
| 457 |
+
html.Div([
|
| 458 |
+
html.Span([
|
| 459 |
+
html.I(className="fas fa-check-circle", style={'marginRight': '8px', 'color': '#28a745'}),
|
| 460 |
+
"Selected for Comparison"
|
| 461 |
+
], style={
|
| 462 |
+
'display': 'inline-flex', 'alignItems': 'center',
|
| 463 |
+
'padding': '6px 12px', 'backgroundColor': '#d4edda',
|
| 464 |
+
'color': '#155724', 'borderRadius': '16px',
|
| 465 |
+
'fontSize': '12px', 'fontWeight': '500', 'marginBottom': '12px'
|
| 466 |
+
})
|
| 467 |
+
]),
|
| 468 |
+
html.Div(result['text'], style={
|
| 469 |
+
'fontFamily': 'monospace', 'backgroundColor': '#fff',
|
| 470 |
+
'padding': '12px', 'borderRadius': '6px', 'border': '2px solid #28a745'
|
| 471 |
+
})
|
| 472 |
+
], style={
|
| 473 |
+
'padding': '16px', 'backgroundColor': '#f8f9fa',
|
| 474 |
+
'borderRadius': '8px', 'border': '1px solid #dee2e6'
|
| 475 |
+
})
|
| 476 |
+
]))
|
| 477 |
+
|
| 478 |
+
return (results_ui, results, {'display': 'block'}, {'display': 'block'},
|
| 479 |
activation_data, activation_data, original_prompt_data, selected_beam_data)
|
| 480 |
|
| 481 |
except Exception as e:
|
plans.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
To Do:
|
| 2 |
- generating with 1 output token doesn't show the "selected" beam, so users can't see the output from the model
|
|
|
|
|
|
|
| 3 |
|
| 4 |
Done:
|
| 5 |
- change attention to entire generated sequence
|
|
|
|
| 1 |
To Do:
|
| 2 |
- generating with 1 output token doesn't show the "selected" beam, so users can't see the output from the model
|
| 3 |
+
- add head index numbers to color swatches in BertViz visualization graph
|
| 4 |
+
- clicking send in the chatbot doesn't immediately show the purple text bubble from the user and the typing animation, there are a couple seconds of nothing. It should immediately populate the text bubble and start the typing animation
|
| 5 |
|
| 6 |
Done:
|
| 7 |
- change attention to entire generated sequence
|