-
Notifications
You must be signed in to change notification settings - Fork 177
Add e2e smoke tests for the new datagen system #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df8499c
Update launch_vllm.py to use calling python env
fynnsu 34516cc
Add e2e online training smoke test
fynnsu c5209cb
Fix hidden states dtype issue
fynnsu 057efbd
Refactor to move logic from test_online_training into utils
fynnsu 4ca1580
Add e2e offline training smoke test
fynnsu 7d172ad
Format
fynnsu 657fe92
Merge branch 'main' into e2e_new_datagen
dsikka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """E2E test for the offline training workflow. | ||
|
|
||
| Exercises the full offline pipeline: | ||
| 1. Prepare data (scripts/prepare_data.py) | ||
| 2. Launch a vLLM server for hidden-state extraction (scripts/launch_vllm.py) | ||
| 3. Generate hidden states offline (scripts/data_generation_offline2.py) | ||
| 4. Stop the vLLM server | ||
| 5. Train a draft model using pre-generated hidden states (scripts/train.py) | ||
| 6. Validate the trained checkpoint via vLLM inference (run_vllm_engine) | ||
| """ | ||
|
|
||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from loguru import logger | ||
|
|
||
| from tests.e2e.vllm.utils import ( | ||
| SCRIPTS_DIR, | ||
| launch_vllm_server, | ||
| prepare_data, | ||
| run_vllm_engine, | ||
| stop_vllm_server, | ||
| ) | ||
|
|
||
| MODEL = "Qwen/Qwen3-0.6B" | ||
| VLLM_PORT = 8322 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def vllm_server(tmp_path): | ||
| """Launch a vLLM server configured for hidden-state extraction.""" | ||
| hidden_states_path = str(tmp_path / "hidden_states") | ||
| process = launch_vllm_server(MODEL, VLLM_PORT, hidden_states_path) | ||
|
|
||
| yield { | ||
| "port": VLLM_PORT, | ||
| "hidden_states_path": hidden_states_path, | ||
| "process": process, | ||
| } | ||
|
|
||
| stop_vllm_server(process) | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
| @pytest.mark.slow | ||
| def test_offline_training( | ||
| tmp_path: Path, prompts: list[list[dict[str, str]]], vllm_server | ||
| ): | ||
| data_path = tmp_path / "data" | ||
| hidden_states_path = tmp_path / "offline_hidden_states" | ||
| save_path = tmp_path / "checkpoints" | ||
| port = vllm_server["port"] | ||
|
|
||
| # Step 1: Prepare data | ||
| prepare_data(MODEL, data_path) | ||
|
|
||
| # Step 2: Generate hidden states offline | ||
| datagen_cmd = [ | ||
| sys.executable, | ||
| str(SCRIPTS_DIR / "data_generation_offline2.py"), | ||
| "--preprocessed-data", | ||
| str(data_path), | ||
| "--endpoint", | ||
| f"http://localhost:{port}/v1", | ||
| "--output", | ||
| str(hidden_states_path), | ||
| "--max-samples", | ||
| "50", | ||
| "--concurrency", | ||
| "4", | ||
| "--validate-outputs", | ||
| ] | ||
| logger.info("Generating hidden states offline: {}", " ".join(datagen_cmd)) | ||
| result = subprocess.run( # noqa: S603 | ||
| datagen_cmd, stderr=subprocess.PIPE, text=True, check=False | ||
| ) | ||
| assert result.returncode == 0, ( | ||
| f"data_generation_offline2.py failed:\n{result.stderr}" | ||
| ) | ||
|
|
||
| # Step 3: Stop the vLLM server to free GPU memory before training | ||
| stop_vllm_server(vllm_server["process"]) | ||
|
|
||
| # Step 4: Train using pre-generated hidden states (no live server needed) | ||
| train_cmd = [ | ||
| sys.executable, | ||
| str(SCRIPTS_DIR / "train.py"), | ||
| "--verifier-name-or-path", | ||
| MODEL, | ||
| "--data-path", | ||
| str(data_path), | ||
| "--hidden-states-path", | ||
| str(hidden_states_path), | ||
| "--save-path", | ||
| str(save_path), | ||
| "--draft-vocab-size", | ||
| "8192", | ||
| "--epochs", | ||
| "1", | ||
| "--lr", | ||
| "3e-4", | ||
| "--total-seq-len", | ||
| "512", | ||
| "--on-missing", | ||
| "raise", | ||
| ] | ||
| logger.info("Running training: {}", " ".join(train_cmd)) | ||
| result = subprocess.run( # noqa: S603 | ||
| train_cmd, stderr=subprocess.PIPE, text=True, check=False | ||
| ) | ||
| assert result.returncode == 0, f"train.py failed:\n{result.stderr}" | ||
|
|
||
| # Step 5: Validate trained checkpoint with vLLM inference | ||
| checkpoint_path = str(save_path / "0") | ||
| run_vllm_engine(model_path=checkpoint_path, tmp_path=tmp_path, prompts=prompts) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """E2E test for the online training workflow. | ||
|
|
||
| Exercises the full pipeline documented in examples/ONLINE_TRAINING.md: | ||
| 1. Prepare data (scripts/prepare_data.py) | ||
| 2. Launch a vLLM server for hidden-state extraction (scripts/launch_vllm.py) | ||
| 3. Train a draft model against the live server (scripts/train.py) | ||
| 4. Validate the trained checkpoint via vLLM inference (run_vllm_engine) | ||
| """ | ||
|
|
||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from loguru import logger | ||
|
|
||
| from tests.e2e.vllm.utils import ( | ||
| SCRIPTS_DIR, | ||
| launch_vllm_server, | ||
| prepare_data, | ||
| run_vllm_engine, | ||
| stop_vllm_server, | ||
| ) | ||
|
|
||
| MODEL = "Qwen/Qwen3-0.6B" | ||
| VLLM_PORT = 8321 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def vllm_server(tmp_path): | ||
| """Launch a vLLM server configured for hidden-state extraction.""" | ||
| hidden_states_path = str(tmp_path / "hidden_states") | ||
| process = launch_vllm_server(MODEL, VLLM_PORT, hidden_states_path) | ||
|
|
||
| yield { | ||
| "port": VLLM_PORT, | ||
| "hidden_states_path": hidden_states_path, | ||
| "process": process, | ||
| } | ||
|
|
||
| stop_vllm_server(process) | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
| @pytest.mark.slow | ||
| def test_online_training( | ||
| tmp_path: Path, prompts: list[list[dict[str, str]]], vllm_server | ||
| ): | ||
| data_path = tmp_path / "data" | ||
| save_path = tmp_path / "checkpoints" | ||
| port = vllm_server["port"] | ||
|
|
||
| # Step 1: Prepare data | ||
| prepare_data(MODEL, data_path) | ||
|
|
||
| # Step 2: Train against live vLLM server | ||
| train_cmd = [ | ||
|
fynnsu marked this conversation as resolved.
|
||
| sys.executable, | ||
| str(SCRIPTS_DIR / "train.py"), | ||
| "--verifier-name-or-path", | ||
| MODEL, | ||
| "--data-path", | ||
| str(data_path), | ||
| "--vllm-endpoint", | ||
| f"http://localhost:{port}/v1", | ||
| "--save-path", | ||
| str(save_path), | ||
| "--draft-vocab-size", | ||
| "8192", | ||
| "--epochs", | ||
| "1", | ||
| "--lr", | ||
| "3e-4", | ||
| "--total-seq-len", | ||
| "512", | ||
| "--on-missing", | ||
| "generate", | ||
| "--on-generate", | ||
| "delete", | ||
| ] | ||
| logger.info("Running training: {}", " ".join(train_cmd)) | ||
| result = subprocess.run( # noqa: S603 | ||
| train_cmd, stderr=subprocess.PIPE, text=True, check=False | ||
| ) | ||
| assert result.returncode == 0, f"train.py failed:\n{result.stderr}" | ||
|
|
||
| # Stop the vLLM server to free GPU memory before running inference | ||
| stop_vllm_server(vllm_server["process"]) | ||
|
|
||
| # Step 3: Validate trained checkpoint with vLLM inference | ||
| checkpoint_path = str(save_path / "0") | ||
| run_vllm_engine(model_path=checkpoint_path, tmp_path=tmp_path, prompts=prompts) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.