Skip to content
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

[Bug]: Local tiktoken fails writing to non-writeable directory in sandboxed macOS application #2607

Open
tnunamak opened this issue Mar 20, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@tnunamak
Copy link

tnunamak commented Mar 20, 2024

What happened?

litellm writes to the filesystem during initialization. I'm building a macOS application and this causes a read-only filesystem error:

Failed to execute script 'main' due to unhandled exception: [Errno 30] Read-only file system: '/private/var/folders/n4/l_tnw4sn7s1572j1t3_vq6mh0000gp/T/AppTranslocation/B62E81E2-6E1E-4F1B-8595-DE7AB482C491/d/Selfie.app/Contents/Frameworks/litellm'

Some investigation shows that it's due to this code, (original PR here).

As a workaround, perhaps this behavior could be disabled or TIKTOKEN_CACHE_DIR could be left alone if it is already set?

Relevant log output

Failed to execute script '__main__' due to unhandled exception: [Errno 30] Read-only file system: '/private/var/folders/n4/l_tnw4sn7s1572j1t3_vq6mh0000gp/T/AppTranslocation/B62E81E2-6E1E-4F1B-8595-DE7AB482C491/d/Selfie.app/Contents/Frameworks/litellm'
Traceback:
Traceback (most recent call last):
  File "selfie/__main__.py", line 12, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "selfie/__init__.py", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "litellm/__init__.py", line 558, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller/loader/pyimo<…>
@maurobender
Copy link

I'm facing the same issue using the codium/pr-agent deployed to a AWS Lamda function (I've also opened an issue there: Codium-ai/pr-agent#909). Since the lamda filesystem is read-only (except for the /tmp folder) I'm getting this error. I've tried the workaround of setting TIKTOKEN_CACHE_DIR to /tmp folder in the filesystem but because of the change tnunamak mentioned before is not possible because of these lines in the code that are overwriting that environment variable.

@Jonas1312
Copy link

I have pretty much the same issue with litellm 1.38.11 and tiktoken 0.7.0 in my docker container.

litellm patches the env var TIKTOKEN_CACHE_DIR, which causes tiktoken to crash:

File \"/opt/app-root/lib64/python3.11/site-packages/tiktoken/load.py\", line 74, in read_file_cached
    with open(tmp_filename, \"wb\") as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/opt/app-root/lib64/python3.11/site-packages/litellm/llms/tokenizers/fb374d419588a4632f3f557e76b4b70aebbca790.e7ca2cd3-f9c8-438e-9f61-6e71d33173af.tmp'

@chai3

This comment was marked as outdated.

@chai3
Copy link

chai3 commented Jun 12, 2024

@tnunamak @maurobender @Jonas1312
#4119 released on v1.40.9
We can use environment variable CUSTOM_TIKTOKEN_CACHE_DIR

@fingon
Copy link

fingon commented Jun 17, 2024

@tnunamak @maurobender @Jonas1312 #4119 released on v1.40.9 We can use environment variable CUSTOM_TIKTOKEN_CACHE_DIR

This comment seems off, it is just TIKTOKEN_CACHE_DIR but it doesn't override it?

@chai3
Copy link

chai3 commented Jun 19, 2024

@fingon Are you still having problems?

litellm/utils.py top level code

os.environ["TIKTOKEN_CACHE_DIR"] = os.getenv("CUSTOM_TIKTOKEN_CACHE_DIR", filename) 

https://github.com/BerriAI/litellm/pull/4119/files#diff-9661b0d8f1d9f48433f2323d1102e963d3098f667f7a25caea79f16fa282f6ddL52-R54

@fingon
Copy link

fingon commented Jun 19, 2024

In our case, the beautiful fix was just to import litellm and set the TIKTOKEN_CACHE_DIR afterwards so this was mostly reference to looking at code (but I might have looked at earlier version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants