fix(infra): remove transformers dependency for api server#5441
Conversation
- Remove transformers import and logging from utils.py - Remove transformers==4.49.0 from requirements/default.txt - Add memory_summary.py for analyzing container memory usage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Greptile Summary
This PR implements a memory optimization by removing the transformers library dependency from the API server requirements. The change involves removing transformers==4.49.0 from backend/requirements/default.txt and eliminating the corresponding import and logging configuration from onyx/natural_language_processing/utils.py.
The optimization leverages Onyx's microservice architecture, where ML functionality is properly separated between the API server and model server components. The transformers package was only being used in the API server for non-critical logging configuration (transformer_logging.set_verbosity_error() and warning suppression), while the actual model inference happens in the dedicated model server that retains the transformers dependency in model_server.txt.
This change demonstrates good architectural separation of concerns - the API server handles business logic and API endpoints while the model server manages ML model operations. The memory savings are significant: API server container memory drops from 805MiB to 718.6MiB (~86MiB reduction), and background worker memory decreases from 6.838GiB to 5.788GiB (~1GB reduction).
The remaining tokenization functionality in utils.py continues to work through the tokenizers library and tiktoken, which handle text processing independently of the full transformers stack.
Confidence score: 4/5
- This PR is safe to merge with low risk as it removes non-critical logging functionality while preserving core features
- Score reflects clear architectural separation and significant memory benefits, with minimal risk of functional regression
- Pay close attention to any runtime errors in areas that might have unexpected transformers dependencies
2 files reviewed, no comments
…pp#5441) Co-authored-by: Edwin Luo <edwinluo@3ef5a334-3d74-4dbf-b1c8-d57dc87d5638.attlocal.net> Co-authored-by: Claude <noreply@anthropic.com>
decent optimization would be to remove transformers pkg from the api server requirements
https://linear.app/danswer/issue/DAN-2551/remove-transformers-dependency-from-api-server
docker stats w current req ->
onyx-stack-background-1 6.838GiB
onyx-stack-api_server-1 805MiB
w/o transformers pkg
onyx-stack-background-1 5.788GiB
onyx-stack-api_server-1 718.6MiB
in terms of regression - yuhong:
the logging is not important
I think it's totally fine to just remove entirely
Description
[Provide a brief description of the changes in this PR]
How Has This Been Tested?
[Describe the tests you ran to verify your changes]
Backporting (check the box to trigger backport action)
Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.
Summary by cubic
Remove the transformers dependency and related logging to reduce memory usage in background workers. Add a memory analysis script to inspect container and per-package import memory impact.
Dependencies
New Features