Fix policy type check in eval_policy function to use unwrapped model#3189
Open
andrearosasco wants to merge 2 commits intohuggingface:mainfrom
Open
Fix policy type check in eval_policy function to use unwrapped model#3189andrearosasco wants to merge 2 commits intohuggingface:mainfrom
andrearosasco wants to merge 2 commits intohuggingface:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes evaluation-time policy type checking when the policy model is wrapped by accelerate (e.g., DDP/FSDP wrappers), by unwrapping before performing isinstance checks.
Changes:
- Add
extract_model_from_paralleland use it to obtainunwrapped_policyfor thePreTrainedPolicy/PeftModeltype checks ineval_policy. - Update the raised
ValueErrormessage to report the unwrapped model type.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from pprint import pformat | ||
| from typing import Any, TypedDict | ||
|
|
||
| from accelerate import accelerator |
There was a problem hiding this comment.
from accelerate import accelerator appears to be an invalid/unused import (it’s not referenced anywhere in this file, and the Accelerate API typically exposes Accelerator, not accelerator). This will likely raise an ImportError at runtime. Remove this import, or replace it with the correct symbol if you intended to use it.
Suggested change
| from accelerate import accelerator |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Andrea Rosasco <andrearosasco.ar@gmail.com>
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.
Title
When using accelerate to run the training the eval function check the policy type which being wrapped raises and exception. This PR fixes it.
Type / Scope
How was this tested (or how to run locally)
Checklist (required before merge)
pre-commit run -a)pytest)