Skip to content

Fix client import error by vendoring transformers constants #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2025
Merged

Conversation

corbt
Copy link
Contributor

@corbt corbt commented Jul 14, 2025

Summary

  • Fixes ART client missing dependencies #230 - ART client missing dependencies error
  • Vendors transformers enum constants into art/dev/model.py to remove the hard dependency
  • Removes fastapi dependency from art/errors.py by using custom exception classes

Context

Issue #230 reported that importing art.Model on the client side fails with ModuleNotFoundError: No module named 'torch' and ModuleNotFoundError: No module named 'transformers'.

This was caused by PR #194 which moved training/inference dependencies to a [backend] group but didn't account for:

  1. art.dev importing transformers at the module level
  2. art.errors importing fastapi's HTTPException

My 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_args
  • DebugOption - from transformers.debug_utils
  • IntervalStrategy - from transformers.trainer_utils
  • SaveStrategy - alias for IntervalStrategy
  • HubStrategy - from transformers.trainer_utils
  • SchedulerType - from transformers.trainer_utils
  • FSDPOption - from transformers.trainer_utils

Each 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 same status_code and detail attributes. This allows the exceptions to work with FastAPI's exception handlers while removing the hard dependency on fastapi for client imports.

Test plan

  • Tested in test/check_deps environment that has only base ART dependencies
  • Verified import art and art.Model(...) work without transformers installed
  • Verified art.dev.EngineArgs() can be instantiated without importing torch/transformers
  • All vendored enums maintain exact same values as transformers originals
  • Custom exceptions maintain compatibility with FastAPI handlers

@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

This fixes issue #230 where importing art.Model on the client side
failed due to missing transformers and fastapi dependencies. The issue
was introduced in PR #194 which moved backend dependencies to an
optional group.

Changes:
1. Vendor all transformers enum constants into art/dev/model.py
   with source comments, removing the hard dependency on transformers
2. Replace fastapi HTTPException with custom ARTError base class
   that maintains compatibility while removing the fastapi dependency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@corbt corbt merged commit 3d28490 into main Jul 14, 2025
2 checks passed
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.

ART client missing dependencies
3 participants