feat: Add two-step generation API (forward_pass + relevance_pass) and forward-only-generation task#13
Open
neerajaryaai wants to merge 18 commits intodlb_v2from
Open
feat: Add two-step generation API (forward_pass + relevance_pass) and forward-only-generation task#13neerajaryaai wants to merge 18 commits intodlb_v2from
neerajaryaai wants to merge 18 commits intodlb_v2from
Conversation
…lize_dlbacktrace() configurable
…ly-generation for clarity
…d multi-token generation and explanation
- Add SEMANTIC_LAYER_TYPES constant for paper-ready compact visualizations - Add layer_types parameter to visualize_relevance, visualize_relevance_fast, and visualize_relevance_auto - Filter nodes by semantic layer types (MLP, Attention, Normalization, etc.) - Always include Placeholder, Model_Input, and Output nodes for graph connectivity - Export SEMANTIC_LAYER_TYPES from package __init__.py
- Add SEMANTIC_LAYER_TYPES constant for paper-ready compact graphs - Add layer_types parameter to visualize_relevance() and visualize_relevance_fast() - Add compact=True shortcut to visualize_dlbacktrace() API - Implement transitive edge computation to maintain DAG connectivity when intermediate nodes are filtered out - Export SEMANTIC_LAYER_TYPES from package __init__.py - Add _get_node_category() helper to check both layer_name and layer_type (graph stores semantic categories in layer_name, not layer_type) - Fix color map lookup to use semantic categories - Allows proper filtering of DL_Layer, MLP_Layer, Activation, etc. nodes
26d4f70 to
f8f9cf6
Compare
Shows total nodes → filtered nodes count for each filtering mode: - Layer-type filtering (visualize_relevance and visualize_relevance_fast) - Top-k filtering - Threshold filtering - No filtering
d042875 to
75b8a65
Compare
- Add EXCLUDED_NODE_PREFIXES constant and _is_excluded_node() helper - Filter out parameter/bias weight nodes in all filtering modes - Cleaner visualization by hiding internal weight matrices
- use sum() instead of mean() for single tensor relevance (batch=1) - add clarifying comments for mean/max/min computation - consistent handling between visualize_relevance and visualize_relevance_fast
- add visualize_relevance_paginated() for splitting large graphs into pages - add rankdir parameter to visualize_relevance(), visualize_relevance_fast(), visualize_relevance_auto() for TB/LR graph direction - add paginated and max_nodes_per_page params to visualize_dlbacktrace() - pass rankdir through visualize_dlbacktrace() to underlying functions
- add pages_per_row param to visualize_relevance_paginated() and visualize_dlbacktrace() - when pages_per_row > 1, creates combined SVG with pages arranged horizontally - add rankdir param to visualize_relevance_paginated() (default TB for vertical) - pass rankdir through to paginated visualization from visualize_dlbacktrace()
- split pages into rows (pages_per_row pages each) - create separate combined SVG for each row - proper cluster subgraph layout with inter-page edges - show page connections across consecutive pages in same row
- rename row-based to column-based layout (pages_per_row stacks vertically) - use TB rankdir for main graph (vertical cluster stacking) - use LR rankdir inside each page cluster (wider node layout) - better visual flow for sequential page reading
- organize pages into columns (page % num_columns) for proper grid - use orthogonal splines for cleaner inter-page edges - add invisible edges to enforce row ordering across columns - create nested clusters: column clusters containing page clusters - pages flow: col0[p1,p4,p7], col1[p2,p5,p8], col2[p3,p6,p9] for Nx3
d70f67c to
45bf165
Compare
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.
Summary
This PR introduces a new
forward-only-generationtask type torun_task()that enables fast token generation without computing relevance scores. This is useful when users only need generated tokens and want to minimize memory usage and latency.It also adds a two-step API (
forward_pass()+relevance_pass()) that decouples multi-token generation from relevance computation, giving users full control over when and which tokens to explain.Changes
New Feature:
forward-only-generationTask"forward-only-generation"torun_task()methodeos_token_idparameternode_iobetween generation steps to reduce memory footprintImproved Visualization API
showandinline_formatparameters tovisualize_dlbacktrace()methodNew Feature: Two-Step
forward_pass()+relevance_pass()APIforward_pass()— Runs autoregressive generation for N tokens, storing per-stepnode_iosnapshots efficiently:input_values,output_values,layer_hyperparams); shallow-copies immutable graph metadatagc.collect()between stepsgenerated_token_ids,complete_sequence, andnum_stepsrelevance_pass()— Computes relevance for selected tokens from a priorforward_pass():self.node_io_trace(populated byforward_pass())token_indicesto explain specific steps (e.g.,[0, 4, 9]) or all steps (None){'step_index', 'token_id', 'relevance'}dictsclear_traces()— Frees all stored snapshots, relevance data, and GPU cacheUsage Examples