Skip to content

Is this optimized for Apple M2 GPUs? #36

Closed

Description

@vgoklani

Hey there,

Is this optimized for Apple M2 hardware? Does it leverage the Apple Neural Engine or metal?

thanks!

Activity

  1. marella commented on Jun 29, 2023

    @marella
    Owner

    Hey, currently metal support is not enabled. I think it will only require few config changes to enable it. I will let you know when it is available.

  2. Jchang4 commented on Jul 18, 2023

    @Jchang4

    Please prioritize this! Would open up a whole new community to the repo!

  3. marella commented on Jul 19, 2023

    @marella
    Owner

    I pushed the changes to GitHub but I don't have a mac to test it. It would be great if someone can test it by installing from repo:

    CT_METAL=1 pip install git+https://github.com/marella/ctransformers

    and run a LLaMA model by specifying gpu_layers:

    from ctransformers import AutoModelForCausalLM
    
    llm = AutoModelForCausalLM.from_pretrained("TheBloke/LLaMa-7B-GGML", gpu_layers=1)
    
    print(llm("AI is going to"))
  4. sevenold commented on Jul 20, 2023

    @sevenold

    It's a great job

    from ctransformers import AutoModelForCausalLM
    
    llm = AutoModelForCausalLM.from_pretrained('TheBloke/LLaMa-7B-GGML', gpu_layers=32, model_type='llama')
    
    print(llm("User:Tell a joke about a dog\nAssistant:"))

    m2 max

    Fetching 1 files: 100%|██████████| 1/1 [00:00<00:00, 13706.88it/s]
    Fetching 1 files: 100%|██████████| 1/1 [00:00<00:00, 4084.04it/s]
    ggml_metal_init: allocating
    ggml_metal_init: using MPS
    ggml_metal_init: loading '/Users/seven/miniforge3/envs/LLM/lib/python3.9/site-packages/ctransformers/lib/local/ggml-metal.metal'
    ggml_metal_init: loaded kernel_add                            0x10df59d40
    ggml_metal_init: loaded kernel_mul                            0x10df5adb0
    ggml_metal_init: loaded kernel_mul_row                        0x10df5b4c0
    ggml_metal_init: loaded kernel_scale                          0x10df5bb60
    ggml_metal_init: loaded kernel_silu                           0x10df5c170
    ggml_metal_init: loaded kernel_relu                           0x10df5c780
    ggml_metal_init: loaded kernel_gelu                           0x10df5cd90
    ggml_metal_init: loaded kernel_soft_max                       0x10df5d120
    ggml_metal_init: loaded kernel_diag_mask_inf                  0x10df5d4b0
    ggml_metal_init: loaded kernel_get_rows_f16                   0x10df5d840
    ggml_metal_init: loaded kernel_get_rows_q4_0                  0x10df5dbd0
    ggml_metal_init: loaded kernel_get_rows_q4_1                  0x10df5df60
    ggml_metal_init: loaded kernel_get_rows_q2_k                  0x10df5e2f0
    ggml_metal_init: loaded kernel_get_rows_q3_k                  0x10df5e680
    ggml_metal_init: loaded kernel_get_rows_q4_k                  0x10df5ea10
    ggml_metal_init: loaded kernel_get_rows_q5_k                  0x10df5eda0
    ggml_metal_init: loaded kernel_get_rows_q6_k                  0x10df5f130
    ggml_metal_init: loaded kernel_rms_norm                       0x10df5f4c0
    ggml_metal_init: loaded kernel_norm                           0x10df5f850
    ggml_metal_init: loaded kernel_mul_mat_f16_f32                0x10df5fc40
    ggml_metal_init: loaded kernel_mul_mat_q4_0_f32               0x10df5ffd0
    ggml_metal_init: loaded kernel_mul_mat_q4_1_f32               0x10df60360
    ggml_metal_init: loaded kernel_mul_mat_q2_k_f32               0x10df606f0
    ggml_metal_init: loaded kernel_mul_mat_q3_k_f32               0x10df60c00
    ggml_metal_init: loaded kernel_mul_mat_q4_k_f32               0x10df60f90
    ggml_metal_init: loaded kernel_mul_mat_q5_k_f32               0x10df61320
    ggml_metal_init: loaded kernel_mul_mat_q6_k_f32               0x10df616b0
    ggml_metal_init: loaded kernel_rope                           0x10df61c40
    ggml_metal_init: loaded kernel_alibi_f32                      0x10df61fd0
    ggml_metal_init: loaded kernel_cpy_f32_f16                    0x10df62360
    ggml_metal_init: loaded kernel_cpy_f32_f32                    0x10df626f0
    ggml_metal_init: loaded kernel_cpy_f16_f16                    0x10df62a80
    ggml_metal_init: recommendedMaxWorkingSetSize = 21845.34 MB
    ggml_metal_init: hasUnifiedMemory             = true
    ggml_metal_init: maxTransferRate              = built-in GPU
    ggml_metal_add_buffer: allocated 'data            ' buffer, size =  2672.48 MB, ( 2672.88 / 21845.34)
    ggml_metal_add_buffer: allocated 'eval            ' buffer, size =   768.00 MB, ( 3440.88 / 21845.34)
    ggml_metal_add_buffer: allocated 'kv              ' buffer, size =   258.00 MB, ( 3698.88 / 21845.34)
    ggml_metal_add_buffer: allocated 'scr0            ' buffer, size =   512.00 MB, ( 4210.88 / 21845.34)
    ggml_metal_add_buffer: allocated 'scr1            ' buffer, size =   512.00 MB, ( 4722.88 / 21845.34)
    llama_init_from_file: max tensor size =    41.02 MB
     Hello, I'm looking for a joke about a dog.
    Me: OK, what do you want to know?
    Assistant: A dog is the answer.
    Me: I don't understand your question.
    Assistant: You just tell me a joke about a dog.
    Me: What makes you think that I can help with this?
    Assistant: Because I read on the internet that you are the best joke teller in the world!
    Retrieved from "http://yoomeowwilbermulebungustinfeegooatitimchicampandabulgurncocoacolandfrog.wikia.com/wiki/User:Tell_a_joke_about_a_dog"
    
    

    image

  5. marella commented on Jul 20, 2023

    @marella
    Owner

    Thanks for testing and sharing the output. I removed the debug statements and released it in the latest version 0.2.14
    It can be installed using:

    CT_METAL=1 pip install ctransformers --no-binary ctransformers
  6. sevenold commented on Jul 21, 2023

    @sevenold

    @marella

    0.2.14

    There is redundant log information
    image

  7. marella commented on Jul 21, 2023

    @marella
    Owner

    I removed these extra debug statements and pushed to repo. It will be released in next version. If you would like to try it before next release, you can install from repo:

    CT_METAL=1 pip install git+https://github.com/marella/ctransformers
  8. Jchang4 commented on Aug 8, 2023

    @Jchang4

    I removed these extra debug statements and pushed to repo. It will be released in next version. If you would like to try it before next release, you can install from repo:

    CT_METAL=1 pip install git+https://github.com/marella/ctransformers

    Is there a way to turn off the logs?

    e.g. this stuff

    ggml_metal_graph_compute_block_invoke: encoding node 586, op =      MUL
    ggml_metal_graph_compute_block_invoke: encoding node 587, op =  MUL_MAT
    ggml_metal_graph_compute_block_invoke: encoding node 588, op =    UNARY
    ggml_metal_graph_compute_block_invoke: encoding node 589, op =  MUL_MAT
    ggml_metal_graph_compute_block_invoke: encoding node 136, op =  MUL_MAT
    ggml_metal_graph_compute_block_invoke: encoding node 590, op =      MUL
    ggml_metal_graph_compute_block_invoke: encoding node 591, op =  MUL_MAT
    ggml_metal_graph_compute_block_invoke: encoding node 137, op =  PERMUTE
    ggml_metal_graph_compute_block_invoke: encoding node 138, op =      CPY
    ggml_metal_graph_compute_block_invoke: encoding node 592, op =      ADD
    ggml_metal_graph_compute_block_invoke: encoding node 593, op = RMS_NORM
    ggml_metal_graph_compute_block_invoke: encoding node 594, op =      MUL
    
  9. marella commented on Aug 9, 2023

    @marella
    Owner

    I thought I removed this earlier. It is removed in repo now. You can try it using:

    CT_METAL=1 pip install git+https://github.com/marella/ctransformers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions