Skip to content

Move cfg.validate() earlier to fix NoneType error with --policy.path#2782

Merged
imstevenpmwork merged 2 commits into
huggingface:mainfrom
samet-rob:fix-policy-path-error
Jan 12, 2026
Merged

Move cfg.validate() earlier to fix NoneType error with --policy.path#2782
imstevenpmwork merged 2 commits into
huggingface:mainfrom
samet-rob:fix-policy-path-error

Conversation

@samet-rob
Copy link
Copy Markdown
Contributor

Title

fix(train): initialize policy before accelerator creation

Type / Scope

  • Type: Bug
  • Scope: lerobot_train

Summary / Motivation

When training with --policy.path, the cfg.policy object remains None until cfg.validate() is explicitly called. This is due to the custom argument filtering in the parser that handles loading configs from local or hub paths. Currently, the code attempts to access cfg.policy.device to initialize the Accelerator before cfg.validate() is executed, leading to an AttributeError: 'NoneType' object has no attribute 'device'. This change moves the validation step to the beginning of the training pipeline to ensure the policy is correctly initialized from the provided path before being accessed.

Related issues

  • Fixes: # (if any)

What changed

  • Moved cfg.validate() call to the beginning of the train() function in src/lerobot/scripts/lerobot_train.py.
  • This ensures cfg.policy is populated when using --policy.path before it's used for device configuration in Accelerator.

How was this tested

  • Manual verification by running training with the --policy.path argument, which previously crashed with AttributeError.

How to run locally (reviewer)

  • Run a training job using a pretrained policy path:

    python src/lerobot/scripts/lerobot_train.py \
      --policy.path=lerobot/smolvla_base \
      --dataset.repo_id=your/dataset \
      --policy.device=cuda

Checklist (required before merge)

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

Reviewer notes

  • The change is minimal and only affects the order of initialization. It is necessary because draccus doesn't handle the --policy.path logic natively, and our validate() method is what actually loads the policy config into the cfg object.

@imstevenpmwork imstevenpmwork self-requested a review January 12, 2026 17:21
Copy link
Copy Markdown
Collaborator

@imstevenpmwork imstevenpmwork left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@imstevenpmwork imstevenpmwork merged commit d0f57f5 into huggingface:main Jan 12, 2026
8 checks passed
sandhya-cb pushed a commit to sandhya-cb/lerobot-clutterbot that referenced this pull request Jan 28, 2026
lu391see pushed a commit to lu391see/lerobot_tactile that referenced this pull request Mar 24, 2026
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