Skip to content

Validate explicitly-provided adapter_model path in ModelParams#2321

Closed
idoudali wants to merge 1 commit intoidoudali/config-exceptionsfrom
idoudali/adapter-model-checks
Closed

Validate explicitly-provided adapter_model path in ModelParams#2321
idoudali wants to merge 1 commit intoidoudali/config-exceptionsfrom
idoudali/adapter-model-checks

Conversation

@idoudali
Copy link
Copy Markdown
Contributor

@idoudali idoudali commented Mar 26, 2026

Depends on #2319

Description

Fail fast with ConfigFileNotFoundError when adapter_model is set but doesn't point to a directory containing adapter_config.json, preventing confusing downstream errors during model loading.

Fixes OPE-1851

Related issues

Fixes # (issue)

Before submitting

  • This PR only changes documentation. (You can ignore the following checks in that case)
  • Did you read the contributor guideline Pull Request guidelines?
  • Did you link the issue(s) related to this PR in the section above?
  • Did you add / update tests where needed?

Reviewers

At least one review from a member of oumi-ai/oumi-staff is required.

@idoudali idoudali requested a review from oelachqar March 26, 2026 16:13
@idoudali idoudali self-assigned this Mar 26, 2026
Copilot AI review requested due to automatic review settings March 26, 2026 16:13
@idoudali idoudali force-pushed the idoudali/config-exceptions branch from 14e626c to 35745d5 Compare March 26, 2026 16:19
Copy link
Copy Markdown
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

This PR makes ModelParams.finalize_and_validate() fail fast when an explicitly provided adapter_model doesn’t resolve to an adapter_config.json, raising ConfigFileNotFoundError to avoid later, more confusing model-loading failures.

Changes:

  • Add explicit validation of adapter_model via find_adapter_config_file() and raise ConfigFileNotFoundError when not found.
  • Update and extend unit tests to cover valid explicit adapter dirs and multiple failure modes (missing path, missing config, HF validation error).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

File Description
src/oumi/core/configs/params/model_params.py Adds explicit adapter_model validation and raises ConfigFileNotFoundError when adapter_config.json can’t be resolved.
tests/unit/core/configs/params/test_model_params.py Updates existing adapter_model test to use a real temp adapter dir and adds new negative tests for explicit adapter_model validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +316 to +322
except (OSError, HFValidationError):
adapter_config_file = None
if not adapter_config_file or not Path(adapter_config_file).is_file():
raise ConfigFileNotFoundError(
f"adapter_config.json not found for adapter_model: "
f"'{self.adapter_model}'. Ensure this path points to a valid "
f"LoRA adapter directory containing adapter_config.json."
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The exception handling here discards the underlying exception by setting adapter_config_file = None. Consider capturing the exception as e and raising ConfigFileNotFoundError(...) from e (or at least logging type(e).__name__ at debug) so users can tell whether the failure was a missing local path, an invalid HF repo id, permission error, etc.

Suggested change
except (OSError, HFValidationError):
adapter_config_file = None
if not adapter_config_file or not Path(adapter_config_file).is_file():
raise ConfigFileNotFoundError(
f"adapter_config.json not found for adapter_model: "
f"'{self.adapter_model}'. Ensure this path points to a valid "
f"LoRA adapter directory containing adapter_config.json."
except (OSError, HFValidationError) as e:
raise ConfigFileNotFoundError(
f"adapter_config.json not found for adapter_model: "
f"'{self.adapter_model}'. Ensure this path points to a valid "
f"LoRA adapter directory containing adapter_config.json."
) from e
if not Path(adapter_config_file).is_file():
raise ConfigFileNotFoundError(
f"adapter_config.json not found for adapter_model: "
f"'{self.adapter_model}'. Ensure this path points to a valid "
f"LoRA adapter directory containing adapter_config.json."

Copilot uses AI. Check for mistakes.
Comment on lines +321 to +322
f"'{self.adapter_model}'. Ensure this path points to a valid "
f"LoRA adapter directory containing adapter_config.json."
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The error text says "Ensure this path points to a valid LoRA adapter directory" but adapter_model can also be a Hugging Face Hub repo id (and failures can be auth/network-related). Consider wording this as "local directory or HF Hub repo id containing adapter_config.json" to avoid misleading guidance.

Suggested change
f"'{self.adapter_model}'. Ensure this path points to a valid "
f"LoRA adapter directory containing adapter_config.json."
f"'{self.adapter_model}'. Ensure this value is a local directory "
f"or HF Hub repo id containing adapter_config.json and that it is "
f"accessible (e.g., correct name, permissions, and network)."

Copilot uses AI. Check for mistakes.
Comment on lines +101 to +104
def test_explicit_adapter_model_nonexistent_path():
"""Explicitly-set adapter_model that doesn't exist raises error."""
params = ModelParams(
model_name="base_model", adapter_model="/nonexistent/adapter_path"
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This test hardcodes an absolute "/nonexistent/..." path. To avoid brittleness across environments (and to keep tests hermetic), prefer using tmp_path / "does_not_exist" (without creating it) as the nonexistent adapter path.

Suggested change
def test_explicit_adapter_model_nonexistent_path():
"""Explicitly-set adapter_model that doesn't exist raises error."""
params = ModelParams(
model_name="base_model", adapter_model="/nonexistent/adapter_path"
def test_explicit_adapter_model_nonexistent_path(tmp_path: Path):
"""Explicitly-set adapter_model that doesn't exist raises error."""
params = ModelParams(
model_name="base_model", adapter_model=str(tmp_path / "does_not_exist")

Copilot uses AI. Check for mistakes.
@idoudali idoudali force-pushed the idoudali/adapter-model-checks branch from ddc2b75 to bd15c23 Compare March 26, 2026 16:20
@idoudali idoudali force-pushed the idoudali/config-exceptions branch from 35745d5 to 9c851f3 Compare March 27, 2026 11:56
@idoudali idoudali force-pushed the idoudali/adapter-model-checks branch from bd15c23 to b2ddb95 Compare March 27, 2026 13:59
@idoudali idoudali force-pushed the idoudali/config-exceptions branch from 9c851f3 to e5f549f Compare March 27, 2026 14:33
Fail fast with ConfigFileNotFoundError when adapter_model is set but
doesn't point to a directory containing adapter_config.json, preventing
confusing downstream errors during model loading.

Fixes OPE-1851
@idoudali idoudali force-pushed the idoudali/adapter-model-checks branch from b2ddb95 to 5237a20 Compare March 27, 2026 15:48
Comment on lines +322 to +326
raise ConfigFileNotFoundError(
f"adapter_config.json not found for adapter_model: "
f"'{self.adapter_model}'. Ensure this path points to a valid "
f"LoRA adapter directory containing adapter_config.json."
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The code raises ConfigFileNotFoundError, which is not defined, causing a NameError at runtime. The correct exception class is OumiConfigFileNotFoundError.
Severity: CRITICAL

Suggested Fix

Replace the undefined ConfigFileNotFoundError on line 322 with the correct, imported exception class OumiConfigFileNotFoundError. Also, update the corresponding test cases in tests/unit/core/configs/params/test_model_params.py to expect OumiConfigFileNotFoundError.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/oumi/core/configs/params/model_params.py#L322-L326

Potential issue: The validation logic for `adapter_model` raises
`ConfigFileNotFoundError` if an `adapter_config.json` file is not found. However, this
exception class is not defined or imported. The correct, imported exception class is
`OumiConfigFileNotFoundError`, which is used in a similar check elsewhere in the same
file. This will cause the application to crash with a `NameError: name
'ConfigFileNotFoundError' is not defined` instead of providing the intended
user-friendly error message. The associated tests also incorrectly try to catch the
undefined exception.

Did we get this right? 👍 / 👎 to inform future reviews.

@oelachqar oelachqar closed this Apr 14, 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.

3 participants