Fix client import error by vendoring transformers constants #232
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.
Summary
art/dev/model.py
to remove the hard dependencyart/errors.py
by using custom exception classesContext
Issue #230 reported that importing
art.Model
on the client side fails withModuleNotFoundError: No module named 'torch'
andModuleNotFoundError: No module named 'transformers'
.This was caused by PR #194 which moved training/inference dependencies to a
[backend]
group but didn't account for:art.dev
importing transformers at the module levelart.errors
importing fastapi's HTTPExceptionMy apologies for not testing the client import path properly in that PR.
Solution
This PR takes a two-pronged approach to fix the client import issues:
1. Vendor transformers constants
Instead of using lazy imports (which would complicate the codebase), this PR vendors all the transformers enum constants that
art.dev.model
needs:OptimizerNames
- from transformers.training_argsDebugOption
- from transformers.debug_utilsIntervalStrategy
- from transformers.trainer_utilsSaveStrategy
- alias for IntervalStrategyHubStrategy
- from transformers.trainer_utilsSchedulerType
- from transformers.trainer_utilsFSDPOption
- from transformers.trainer_utilsEach vendored constant includes a comment indicating its source for future reference.
2. Remove fastapi dependency
Replaced fastapi's HTTPException with a custom
ARTError
base class that has the samestatus_code
anddetail
attributes. This allows the exceptions to work with FastAPI's exception handlers while removing the hard dependency on fastapi for client imports.Test plan
test/check_deps
environment that has only base ART dependenciesimport art
andart.Model(...)
work without transformers installedart.dev.EngineArgs()
can be instantiated without importing torch/transformers@bradhilton Could you please review and make sure this approach looks reasonable? Happy to adjust if you'd prefer a different solution.
🤖 Generated with Claude Code