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

metal : add backend function to check device family support #1547

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

ggerganov
Copy link
Owner

ref #1387

When Apple7 is not supported, we fallback to CPU automatically

@ggerganov ggerganov merged commit 0ba365f into master Nov 24, 2023
72 checks passed
@ggerganov ggerganov deleted the gg/check-apple-family branch November 24, 2023 10:37
@@ -1078,6 +1078,11 @@ static ggml_backend_t whisper_backend_init(const whisper_context_params & params
if (!backend_gpu) {
WHISPER_LOG_ERROR("%s: ggml_backend_metal_init() failed\n", __func__);
}
if (!ggml_backend_metal_supports_family(backend_gpu, 7)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is correct. It should disable it on family 7 and older.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Are you sure? M2 Ultra is Apple8 and it works fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Older would be Apple 6, 5, etc.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah sorry, yes.

I thought somebody said that Apple7 works?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, should be disabled on family 6 and older. I got confused since it's disabling 7 here.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yup, let me know if you still think this needs to be changed.

The way it is written now it should do the following:

  • Apple 1-6 -> fallback to CPU
  • Apple 7, 8, 9, .. -> use GPU

The assumption is that if Apple7 is supported, then due to backwards compatibility all previous families (1-6) are also supported, so no need to check for those individually.

Copy link
Contributor

Choose a reason for hiding this comment

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

the order seems to be wrong, we should check the compatibility first, then call ggml_backend_metal_init. otherwise it still crash on lower device.

Copy link
Contributor

@Josscii Josscii Nov 25, 2023

Choose a reason for hiding this comment

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

I think we should do something like this:

#ifdef GGML_USE_METAL
    if (!ggml_backend_metal_supports_family(backend_gpu, 7)) {
        WHISPER_LOG_ERROR("%s: Metal GPU does not support family 7 - falling back to CPU\n", __func__);
    } else if (params.use_gpu) {
        WHISPER_LOG_INFO("%s: using Metal backend\n", __func__);
        ggml_metal_log_set_callback(whisper_log_callback_default, nullptr);
        backend_gpu = ggml_backend_metal_init();
        if (!backend_gpu) {
            WHISPER_LOG_ERROR("%s: ggml_backend_metal_init() failed\n", __func__);
        }
    }
#endif

but right now, it's not possible, because we can't get the ggml_backend_t if it is not inited, I think there need some refactor

Copy link
Contributor

Choose a reason for hiding this comment

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

Was this done?

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems done, right now it do check in ggml_backend_metal_init to avoid crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants