Skip to content

Fix policy type check in eval_policy function to use unwrapped model#3189

Open
andrearosasco wants to merge 2 commits intohuggingface:mainfrom
andrearosasco:fix/accelerate_eval
Open

Fix policy type check in eval_policy function to use unwrapped model#3189
andrearosasco wants to merge 2 commits intohuggingface:mainfrom
andrearosasco:fix/accelerate_eval

Conversation

@andrearosasco
Copy link

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

  • Type: Bug
  • Scope: eval

How was this tested (or how to run locally)

  • Running a training with periodic evaluations

Checklist (required before merge)

  • Linting/formatting run (pre-commit run -a)
  • All tests pass locally (pytest)
  • Documentation updated
  • CI is green

Copilot AI review requested due to automatic review settings March 20, 2026 12:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_parallel and use it to obtain unwrapped_policy for the PreTrainedPolicy / PeftModel type checks in eval_policy.
  • Update the raised ValueError message 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
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Andrea Rosasco <andrearosasco.ar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants