langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
51.81k stars 7.51k forks source link

When I manually compile the interface service using the API, the following error occurs.. #8744

Closed kyomic closed 1 month ago

kyomic commented 1 month ago

Self Checks

Dify version

0.8.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

ENV:

Darwin 192.168.1.7 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 21 21:18:39 PDT 2022; root:xnu-6153.141.66~1/RELEASE_X86_64 x86_64

MacOS 10.15.7, intel cpu

$ cd api
$ poetry run python -m flask run --host 0.0.0.0 --port=5001 --debug
Fatal Python error: Segmentation fault

Current thread 0x000000010c487dc0 (most recent call first):
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1176 in create_module
  File "<frozen importlib._bootstrap>", line 571 in module_from_spec
  File "<frozen importlib._bootstrap>", line 674 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/pyarrow/__init__.py", line 65 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/pandas/compat/pyarrow.py", line 8 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/pandas/compat/__init__.py", line 27 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/pandas/__init__.py", line 26 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/bigquery/table.py", line 28 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/bigquery/job/copy_.py", line 22 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/bigquery/job/__init__.py", line 27 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1078 in _handle_fromlist
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/bigquery/_job_helpers.py", line 47 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1078 in _handle_fromlist
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/bigquery/client.py", line 69 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/bigquery/__init__.py", line 35 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1078 in _handle_fromlist
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/aiplatform/datasets/column_names_dataset.py", line 24 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/aiplatform/datasets/__init__.py", line 19 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/google/cloud/aiplatform/__init__.py", line 26 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/vertexai/__init__.py", line 17 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 992 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/Users/wangxk/git/dify/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py", line 9 in <module>
  ...

Extension modules: markupsafe._speedups, greenlet._greenlet, zope.interface._zope_interface_coptimizations, gevent.libev.corecext, gevent._gevent_c_greenlet_primitives, gevent._gevent_c_hub_local, gevent._gevent_c_waiter, gevent._gevent_c_hub_primitives, gevent._gevent_c_ident, gevent._gevent_cgreenlet, gevent._gevent_c_abstract_linkable, gevent._gevent_c_semaphore, gevent._gevent_clocal, gevent._gevent_cevent, gevent._gevent_cqueue, grpc._cython.cygrpc, gevent._gevent_c_imap, yaml._yaml, sqlalchemy.cyextension.collections, sqlalchemy.cyextension.immutabledict, sqlalchemy.cyextension.processors, sqlalchemy.cyextension.resultproxy, sqlalchemy.cyextension.util, _cffi_backend, hiredis.hiredis, crcmod._crcfunext, _brotli, zstandard.backend_c, charset_normalizer.md, multidict._multidict, yarl._helpers_c, yarl._quoting_c, aiohttp._helpers, aiohttp._http_writer, aiohttp._http_parser, aiohttp._websocket, frozenlist._frozenlist, google._upb._message, gmpy2.gmpy2, numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, torch._C, torch._C._fft, torch._C._linalg, torch._C._nn, torch._C._sparse, torch._C._special, regex._regex, PIL._imaging (total: 60)
Segmentation fault: 11

✔️ Expected Behavior

The Docker-related containers are running normally.

❌ Actual Behavior

some LLM error!

dosubot[bot] commented 1 month ago

Hello @kyomic! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve any issues you encounter.

The segmentation fault you're encountering when running the Dify API on MacOS 10.15.7 with an Intel CPU seems to be related to the pyarrow library. This is a known issue with pyarrow on certain MacOS versions and hardware configurations.

Here are a few steps you can try to resolve this issue:

  1. Update pyarrow and Dependencies: Ensure that you have the latest version of pyarrow and its dependencies. You can update pyarrow using poetry:

    poetry add pyarrow --upgrade
  2. Reinstall pyarrow: Sometimes, simply reinstalling the library can resolve the issue:

    poetry remove pyarrow
    poetry add pyarrow
  3. Use a Different Python Version: There might be compatibility issues with the specific Python version you are using. Try using a different Python version (e.g., Python 3.9):

    poetry env use 3.9
    poetry install
  4. Check for MacOS Updates: Ensure that your MacOS is up to date. Sometimes, system updates can resolve compatibility issues.

  5. Use a Virtual Environment: If you are not already using a virtual environment, consider setting one up to isolate dependencies:

    python -m venv venv
    source venv/bin/activate
    poetry install
  6. Run with Docker: If the issue persists, consider running the Dify API within a Docker container to avoid host system compatibility issues. The Dify documentation provides steps to start the Docker stack:

    cd ../docker
    cp middleware.env.example middleware.env
    docker compose -f docker-compose.middleware.yaml --profile weaviate -p dify up -d
    cd ../api
    poetry run python -m flask run --host 0.0.0.0 --port=5001 --debug

If none of these steps resolve the issue, you might need to look into more specific compatibility problems between pyarrow and MacOS 10.15.7 with an Intel CPU, or consider reaching out to the pyarrow community for further assistance.

To continue talking to Dosu, mention @dosu.

crazywoola commented 1 month ago

This is not related to the dify itself. If you choose to use the source code to start the application, we assume you have the basic knowledge of how to install dependancies.

kyomic commented 1 month ago

On my Mac, when I start the API service, I get the following error:

Segmentation fault: 11

Then I added some debugging code in app.py, and the above error was raised.

import faulthandler
faulthandler.enable()

Report the above error.It seems like a circular import in Python or a Python version issue error.

Current thread 0x000000010c487dc0 (most recent call first):
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1176 in create_module
  File "<frozen importlib._bootstrap>", line 571 in module_from_spec
  File "<frozen importlib._bootstrap>", line 674 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/pyarrow/__init__.py", line 65 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
...

I believe I know how to install package dependencies correctly. I compiled the Dockerfile and was able to start the API service, as shown below:

None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration, and file/data utilities can be used.
sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml
sagemaker.config INFO - Not applying SDK defaults from location: /root/.config/sagemaker/config.yaml
2024-09-27 06:19:43,804.804 WARNING [MainThread] [ext_mail.py:51] - MAIL_TYPE is not set
[2024-09-27 06:19:45 +0000] [1] [INFO] Starting gunicorn 22.0.0
[2024-09-27 06:19:45 +0000] [1] [INFO] Listening at: http://0.0.0.0:5001 (1)
[2024-09-27 06:19:45 +0000] [1] [INFO] Using worker: gevent
[2024-09-27 06:19:45 +0000] [22] [INFO] Booting worker with pid: 22
[2024-09-27 06:22:02 +0000] [1] [INFO] Handling signal: term
[2024-09-27 06:22:03 +0000] [22] [INFO] Worker exiting (pid: 22)
[2024-09-27 06:22:06 +0000] [1] [ERROR] Worker (pid:21) exited with code 1
[2024-09-27 06:22:06 +0000] [1] [ERROR] Worker (pid:21) exited with code 1.
[2024-09-27 06:22:06 +0000] [1] [INFO] Shutting down: Master

Has anyone else successfully run this project on an older Mac with version 10.15?

Let me know if any part needs to be further modified!

kyomic commented 4 weeks ago

Thank you, Google! I have found the solution: downgrading pyarrow to version 15.0.2 should work, as the current version 17.0.0 has unknown compatibility issues. You can do this by running:

pip uninstall pyarrow
pip install pyarrow==15.0.2