{ "cells": [ { "cell_type": "markdown", "id": "cell-0", "metadata": {}, "source": [ "# Extract Residual Stream Activations\n", "\n", "This notebook demonstrates how to capture residual-stream activations during\n", "vLLM inference using the async engine and vllm-lens." ] }, { "cell_type": "markdown", "id": "cell-1", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "cell-2", "metadata": {}, "outputs": [], "source": [ "from vllm import AsyncEngineArgs, AsyncLLMEngine, SamplingParams" ] }, { "cell_type": "markdown", "id": "cell-3", "metadata": {}, "source": [ "## Configuration" ] }, { "cell_type": "code", "execution_count": 2, "id": "cell-4", "metadata": {}, "outputs": [], "source": [ "MODEL = \"facebook/opt-125m\"\n", "PROMPT = \"The future of AI is\"\n", "LAYERS = [0, 2, 5]" ] }, { "cell_type": "markdown", "id": "cell-5", "metadata": {}, "source": [ "## Initialize the Async Engine" ] }, { "cell_type": "code", "execution_count": 3, "id": "cell-6", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b0314366850e4b35b06579ca676ff1ce", "version_major": 2, "version_minor": 0 }, "text/plain": [ "config.json: 0%| | 0.00/651 [00:00, 'debug_dump_path': None, 'cache_dir': '', 'compile_cache_save_format': 'binary', 'backend': 'inductor', 'custom_ops': ['all'], 'splitting_ops': [], 'compile_mm_encoder': False, 'compile_sizes': [], 'compile_ranges_split_points': [2048], 'inductor_compile_config': {'enable_auto_functionalized_v2': False, 'combo_kernels': True, 'benchmark_combo_kernel': True}, 'inductor_passes': {}, 'cudagraph_mode': , 'cudagraph_num_of_warmups': 0, 'cudagraph_capture_sizes': [], 'cudagraph_copy_inputs': False, 'cudagraph_specialize_lora': True, 'use_inductor_graph_partition': False, 'pass_config': {'fuse_norm_quant': True, 'fuse_act_quant': True, 'fuse_attn_quant': False, 'enable_sp': False, 'fuse_gemm_comms': False, 'fuse_allreduce_rms': False}, 'max_cudagraph_capture_size': 0, 'dynamic_shapes_config': {'type': , 'evaluate_guards': False, 'assume_32_bit_indexing': False}, 'local_cache_dir': None, 'fast_moe_cold_start': True, 'static_all_moe_layers': []}\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:58:55 [worker_base.py:283] Injected into for extended collective_rpc calls ['clear_captured_states', 'clear_steering_data', 'get_captured_states', 'install_hooks', 'set_steering_data']\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:58:58 [parallel_state.py:1393] world_size=1 rank=0 local_rank=0 distributed_init_method=tcp://10.242.3.185:60453 backend=nccl\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:58:58 [parallel_state.py:1715] rank 0 in world size 1 is assigned as DP rank 0, PP rank 0, PCP rank 0, TP rank 0, EP rank N/A, EPLB rank N/A\n", "[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0\n", "[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0\n", "[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0\n", "[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0\n", "[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0\n", "[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:58:58 [base.py:106] Offloader set to NoopOffloader\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:58:58 [gpu_model_runner.py:4255] Starting to load model facebook/opt-125m...\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:58:59 [cuda.py:405] Using FLASH_ATTN attention backend out of potential backends: ['FLASH_ATTN', 'FLASHINFER', 'TRITON_ATTN', 'FLEX_ATTENTION'].\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:58:59 [flash_attn.py:587] Using FlashAttention version 3\n", "(EngineCore_DP0 pid=278813) INFO 03-14 09:59:03 [weight_utils.py:561] Time spent downloading weights for facebook/opt-125m: 3.814851 seconds\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7342843d498648ba873e20a6e6f4326d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading pt checkpoint shards: 0% Completed | 0/1 [00:00