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

fix: automatically replace unsupported torch device #2514

Merged
merged 1 commit into from Jan 11, 2024

Conversation

Drincann
Copy link
Contributor

@Drincann Drincann commented Dec 31, 2023

Thank you for your hard work on this fantastic project!

I've been trying to run this project on a Mac Studio with an M2 chip. Following the README instructions, I completed database initialization, model downloading, and other setup steps. However, I encountered a startup failure when launching the service.

The error message indicated: "raise AssertionError('Torch not compiled with CUDA enabled')". This is expected since I am using an M2 chip. Tracing the stack trace, I located the issue in the server/utils.py file, where the 'cuda' device is set:

def get_model_worker_config(model_name: str = None) -> dict:
    from configs.model_config import ONLINE_LLM_MODEL, MODEL_PATH
    from configs.server_config import FSCHAT_MODEL_WORKERS
    from server import model_workers

    config = FSCHAT_MODEL_WORKERS.get("default", {}).copy()
    config.update(ONLINE_LLM_MODEL.get(model_name, {}).copy())
    config.update(FSCHAT_MODEL_WORKERS.get(model_name, {}).copy()) # device: 'cuda' loaded here

    if model_name in ONLINE_LLM_MODEL:
    # ...

    if model_name in MODEL_PATH["llm_model"]:
    # ...
        config["device"] = llm_device(config.get("device"))
    return config

In configs/server_config.py, the 'cuda' device is explicitly set:

FSCHAT_MODEL_WORKERS = {
  # ...

    "chatglm3-6b": {
        "device": "cuda", # here
    },

  # ...
}

Although the current code supports multiple platforms, this 'cuda' setting is not suitable for users with Apple chips. To enhance the robustness of the project and ensure smooth initial startup for Apple chip users with chatglm3-6b, I suggest adding smarter device detection and fallback logic. When the selected device is not supported, the system should automatically switch to other viable options, such as falling back from 'cuda' to 'mps'.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 31, 2023
Copy link
Collaborator

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,会合并

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR merged commit e7bba6b into chatchat-space:master Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants