Add Finetuning Infrastructure#432
Open
Aditya-Gupta26 wants to merge 8 commits into
Open
Conversation
5bed292 to
e0a8f63
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a finetuning workflow for Puffer training/eval (overlay .ini configs, checkpoint “architecture lock”, and parameter-efficient finetuning via freeze/LoRA), and extends the Drive environment with configurable vehicle spawn dimensions plus mixed truck/car spawning.
Changes:
- Add finetune support: checkpoint arch-locking for train/eval,
--finetune-configoverlay layering, optimizer behavior changes for finetune vs resume, and finetune metadata logging. - Implement parameter-efficient finetuning utilities (
freeze_regex, LoRA wrappers, and LoRA-specific optimizer param groups/LR multiplier). - Add Drive spawn dimension ranges and mixed truck spawning; remove the “seconds stopped” observation and adjust feature counts accordingly.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pufferlib/pufferl.py | Adds checkpoint arch-locking, finetune overlay support, LoRA/freezing integration into policy load + optimizer param grouping, and finetune/resume semantics. |
| pufferlib/finetune.py | New module implementing freeze + LoRA wrapping utilities and optimizer param-group construction. |
| pufferlib/ocean/drive/drive.py | Plumbs new spawn dimension + truck spawning parameters from Python into the C env via init kwargs. |
| pufferlib/ocean/drive/binding.c | Unpacks new spawn/truck parameters into the C Drive struct. |
| pufferlib/ocean/drive/drive.h | Adds new Drive fields for spawn/truck parameters; updates spawning logic; removes stopped-time observation feature and related bookkeeping. |
| pufferlib/ocean/drive/datatypes.h | Removes seconds_stopped from Agent. |
| pufferlib/config/ocean/drive.ini | Adds finetune section + spawn/truck params; updates some default policy/env settings. |
| pufferlib/config/ocean/drive_finetune_truck_mixed.ini | Example finetune overlay for mixed truck spawning. |
| pufferlib/config/ocean/drive_finetune_reward.ini | Example finetune overlay using LoRA for reward retuning. |
| pufferlib/config/ocean/drive_finetune_nuplan.ini | Example finetune overlay for nuPlan replay training (LoRA). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+51
to
+68
| ; Per-agent spawn dimensions (meters). Training and eval use independent | ||
| ; ranges so a policy trained on non-car shapes (e.g. trucks) can be eval'd | ||
| ; on matching shapes. width is clipped to <= length at spawn time. | ||
| spawn_length_min = 0.8 | ||
| spawn_length_max = 7.0 | ||
| spawn_width_min = 0.8 | ||
| spawn_width_max = 3.0 | ||
| eval_spawn_length_min = 2.0 | ||
| eval_spawn_length_max = 5.5 | ||
| eval_spawn_width_min = 1.5 | ||
| eval_spawn_width_max = 2.5 | ||
| ; Mixed-population spawn: per-agent P(is_truck). 0.0 (default) preserves | ||
| ; the legacy single-population behavior | ||
| truck_fraction = 0.0 | ||
| truck_spawn_length_min = 9.0 | ||
| truck_spawn_length_max = 15.0 | ||
| truck_spawn_width_min = 2.0 | ||
| truck_spawn_width_max = 2.6 |
Comment on lines
13
to
16
| [policy] | ||
| ; Encoder layer | ||
| input_size = 64 | ||
| input_size = 128 | ||
| encoder_gigaflow = True |
Comment on lines
+337
to
+359
| // Per-agent spawn dimension ranges (training vs eval modes use separate ranges). | ||
| // length: longitudinal extent in meters; width: lateral extent in meters. | ||
| // width is clipped to <= length at spawn time. | ||
| float spawn_length_min; | ||
| float spawn_length_max; | ||
| float spawn_width_min; | ||
| float spawn_width_max; | ||
| float eval_spawn_length_min; | ||
| float eval_spawn_length_max; | ||
| float eval_spawn_width_min; | ||
| float eval_spawn_width_max; | ||
| // Mixed-population spawn: per-agent P(is_truck). When truck_fraction == 0 | ||
| // (default), every agent samples dims from the spawn_*_{min,max} range above | ||
| // and behavior is identical to the single-population path. When > 0, a | ||
| // Bernoulli(truck_fraction) draw at spawn time picks between the car range | ||
| // (spawn_*) and the truck range (truck_spawn_*). Used for co-training a | ||
| // single policy on a realistic mixed-vehicle population (~10% trucks). | ||
| // Eval mode reuses the same truck range; eval_spawn_* still covers cars. | ||
| float truck_fraction; | ||
| float truck_spawn_length_min; | ||
| float truck_spawn_length_max; | ||
| float truck_spawn_width_min; | ||
| float truck_spawn_width_max; |
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.
This PR adds Finetuning Infrastructure to our codebase. IT can be used to running several fine-tuning experiments by providing the respective
.inifiles while runningpuffer train.It also adds support for truck world usage by specifying its dimensions if needed.
Some ini scripts are also added for reference.