Fix/config path - #124
Conversation
| import pandas as pd | ||
| from beartype.typing import Any | ||
| from lightning_fabric.utilities import rank_zero_only | ||
| from lightning.fabric.utilities import rank_zero_only |
There was a problem hiding this comment.
this is just a more modern import pattern for fabric which has been subsumed into lightning.
There was a problem hiding this comment.
Pull request overview
This PR enables the RF3 CLI to work correctly when the package is pip-installed while maintaining compatibility with development installations. The changes follow a similar pattern used in RFD3 for handling both installation modes.
Key changes:
- Updated import statements from
lightning_fabrictolightning.fabricfor consistency with the rest of the codebase - Modified RF3 CLI config path resolution to detect and handle both installed and development modes
- Corrected
pyproject.tomlconfiguration by movinglocal-schemeto the appropriate section
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/foundry/utils/logging.py | Updated Lightning import to use modern lightning.fabric package path |
| src/foundry/utils/ddp.py | Updated Lightning import to use modern lightning.fabric package path |
| pyproject.toml | Moved local-scheme configuration from hooks section to version section (correct location per hatch-vcs) |
| models/rf3/src/rf3/inference.py | Changed config path from PROJECT_ROOT-based to relative path resolution |
| models/rf3/src/rf3/cli.py | Implemented dual-mode config path detection that checks for installed mode first, then falls back to development mode |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _config_path = os.path.join( | ||
| os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "configs" | ||
| ) |
There was a problem hiding this comment.
The config path resolution differs from the cli.py pattern and doesn't properly handle both installed and development modes. While the primary CLI path (via cli.py) works because it initializes Hydra before calling run_inference, direct execution would only work in development mode.
For consistency and robustness, consider matching the cli.py pattern: check if configs exist as a sibling directory first (for installed mode), then fall back to the development path. This would make both entry points handle installation modes consistently.
| _config_path = os.path.join( | |
| os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "configs" | |
| ) | |
| # Prefer a sibling 'configs' directory (installed mode); fall back to the | |
| # development layout where 'configs' lives three levels up. | |
| _sibling_configs = os.path.join(os.path.dirname(__file__), "configs") | |
| _dev_configs = os.path.join( | |
| os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "configs" | |
| ) | |
| _config_path = _sibling_configs if os.path.isdir(_sibling_configs) else _dev_configs |
|
|
||
| # Check if we're in installed mode (configs are sibling to this file) | ||
| # or development mode (configs are ../../../configs) | ||
| if (rf3_file_dir / "configs").exists(): | ||
| # Installed mode | ||
| config_path = str(rf3_file_dir / "configs") | ||
| else: | ||
| # Development mode | ||
| rf3_package_dir = rf3_file_dir.parent.parent # Go up to models/rf3/ | ||
| config_path = str(rf3_package_dir / "configs") |
There was a problem hiding this comment.
The order of checking installed vs development mode is reversed compared to the RFD3 implementation pattern. This checks for installed mode first, which could cause issues if someone has the package installed and is also working in a development environment - it would use the potentially stale installed configs instead of the development ones.
Consider following the RFD3 pattern: check for the development path first, then fall back to the installed path. This ensures that when working in development mode, the development configs are always used.
| # Check if we're in installed mode (configs are sibling to this file) | |
| # or development mode (configs are ../../../configs) | |
| if (rf3_file_dir / "configs").exists(): | |
| # Installed mode | |
| config_path = str(rf3_file_dir / "configs") | |
| else: | |
| # Development mode | |
| rf3_package_dir = rf3_file_dir.parent.parent # Go up to models/rf3/ | |
| config_path = str(rf3_package_dir / "configs") | |
| rf3_package_dir = rf3_file_dir.parent.parent # Go up to models/rf3/ in development | |
| # Check if we're in development mode (configs are ../../../configs) | |
| # or installed mode (configs are sibling to this file) | |
| if (rf3_package_dir / "configs").exists(): | |
| # Development mode | |
| config_path = str(rf3_package_dir / "configs") | |
| else: | |
| # Installed mode | |
| config_path = str(rf3_file_dir / "configs") |
This PR updates the RF3 CLI to enable running RF3 from the command line when pip installed while also maintaining the ability to use the CLI with a dev installation. It uses the same pattern used for the same thing in RFD3.