JSv4 / OpenContracts

Mass document analytics platform based on LlamaIndex, Pgvector, React and Django.
https://JSv4.github.io/OpenContracts/
Apache License 2.0
716 stars 60 forks source link

Solving the cannot allocate memory in static TLS block ERROR #230

Open dr-robert-li opened 1 month ago

dr-robert-li commented 1 month ago

I note that I'm not the only one that has suffered this error in the past:

ERROR 2024-09-25 20:29:16,864 signal 8 281473223794704 Signal handler <bound method DjangoFixup.on_import_modules of <celery.fixups.django.DjangoFixup object at 0xffff94bea1d0>> raised: ImportError('/usr/local/lib/python3.10/site-packages/torch/lib/../../torch.libs/libgomp-804f19d4.so.1.0.0: cannot allocate memory in static TLS block')

In the previously raised issue this was resolved adding this workaround to the local.yml:

services:
  django: &django
    environment:
      - LD_PRELOAD=/usr/local/lib/python3.10/site-packages/torch/lib/../../torch.libs/libgomp-804f19d4.so.1.0.0

This didn't work for me.

When researching this error in other packages (starting with the pytorch repo) and other repos, it appears to be common when dealing with Apple Silicon (M{x}) chipsets.

So after a lot of messing around, I found I could successfully launch a local build with no issues if I explicitly set: platform: linux/amd64 in the local.yml docker compose manifest to force emulation of the architecture probably present on your local machine.

I propose that this small change be added to the main branch:

services:
  django: &django
    build:
      context: .
      args:
        - GITHUB_ACTIONS
      dockerfile: ./compose/local/django/Dockerfile
    image: opencontractserver_local_django
    platform: linux/amd64
    depends_on:
      - postgres
      - redis
      - vector-embedder
      - nlm-ingestor
    volumes:
      - .:/app:z
    env_file:
      - ./.envs/.local/.django
      - ./.envs/.local/.postgres
    ports:
      - "8000:8000"
    command: /start

Also another small ask, can we also add to documentation, especially in quickstart, the need to fill out the DJANGO_SECRET_KEY= and the POSTGRES_USER= / POSTGRES_PASSWORD= in the sample_env files. I know, I was lazy and I just pushed everything through without checking, so definitely user error, but would be good to explicitly point this out.|

Otherwise, thanks! This is a great open source package!

dr-robert-li commented 1 month ago

For reference here is the previously closed issue: https://github.com/JSv4/OpenContracts/issues/135

JSv4 commented 1 month ago

Thanks for the input @dr-robert-li. Both great suggestions. Will try to roll this into some upcoming PRs.