Files
Kijai 8cfbc3e4aa Squashed commit of the following:
commit 0a847cba9d6a906f16866cef55abc3d08591d384
Author: vik <vikhyatk@gmail.com>
Date:   Wed Jan 31 12:31:10 2024 -0800

    bugfix

commit de750a63ec3546c6f2dccde2d90902f314ac1cf8
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 18:33:40 2024 -0800

    clean up inference interface a bit

commit 2ee0cdad0c6c7e981bfe21fb5160319fe328bbd1
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 17:20:12 2024 -0800

    load tokenizer from HF

commit 4c981021959e440b3d3d33a6cb4c7324349587e4
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 17:07:57 2024 -0800

    bugfix

commit d5fa2f95fe1799e5191defa339e06bdfcc079bb8
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 15:45:51 2024 -0800

    stop using torch.jit.script for the vision encoder

    the interface is a little awkward right now, will be fixed shortly

commit cc252f3f5fc54a4d1ea4a41c1849bd458e5eb515
Merge: 0ce7485 d310e37
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 13:33:47 2024 -0800

    Merge pull request #34 from eltociear/patch-1

    Update README.md

commit 0ce7485481f664ed90e90d0e257856e61cfcdc44
Merge: 3f4815b 2329525
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 13:32:49 2024 -0800

    Merge branch 'mazzzystar-main'

commit 232952569a3b2c46d19d0a3bee25032982f8c68d
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 13:32:36 2024 -0800

    add missing newline

commit d310e3739743fee903dd1afd52c572c2b9a23370
Author: Ikko Eltociear Ashimine <eltociear@gmail.com>
Date:   Wed Jan 31 00:13:48 2024 +0900

    Update README.md

    Huggingface -> Hugging Face

commit 53b57032078233856fbca8e19c4e4bd5b7c69586
Merge: aad2073 3f4815b
Author: Ke Fang <myfancoo@qq.com>
Date:   Tue Jan 30 17:19:20 2024 +0800

    Merge branch 'main' into main

commit aad20735513fceac5437a94d7308b55b95dcb216
Author: mazzzystar <2680461921@qq.com>
Date:   Tue Jan 30 17:16:29 2024 +0800

    change from Thread -> Queue to get the full response.

commit 6d497b787af56d56a3c307b1745936bcdc7ea9e9
Author: mazzzystar <2680461921@qq.com>
Date:   Tue Jan 30 17:11:18 2024 +0800

    resolve conflict for stream response.

commit e51173058648ad46875275aed8d6f8a7b595294d
Author: mazzzystar <2680461921@qq.com>
Date:   Tue Jan 30 17:02:53 2024 +0800

    resolve conflict for stream response.

commit 3f4815bd86aabb18724d74ef024adeff6c53914e
Author: vik <vikhyatk@gmail.com>
Date:   Tue Jan 30 00:50:30 2024 -0800

    bring back interactive mode text streaming

commit 948fa7ff49d990fa477b70c5768ad6a793edaf38
Author: mazzzystar <2680461921@qq.com>
Date:   Tue Jan 30 16:49:07 2024 +0800

    support for multi-round chat.

commit 4a2fb46a17ca333a5f53e3787e01bd727058395f
Author: vik <vikhyatk@gmail.com>
Date:   Mon Jan 29 21:50:18 2024 -0800

    simplify resize/cropping in the vision encoder

commit c206a5d4fd1afe0129f2ff6c0aa03bdbd372fddd
Author: vik <vikhyatk@gmail.com>
Date:   Mon Jan 29 21:45:03 2024 -0800

    detect and use appropriate device/dtype

commit 38af98596e59f2a6c25c6b52b2bd5a672dab4144
Merge: 15d5dd7 70c5358
Author: vik <vikhyatk@gmail.com>
Date:   Mon Jan 29 03:43:58 2024 -0800

    Merge pull request #31 from markusheimerl/main

    Refactored to reduce code size

commit 70c5358887477991d91241fd66b597a3afc44a33
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:40:45 2024 +0000

    Refactor code to improve readability and maintainability

commit 12f61ce90786c8d5664cbbd0d8b9701033b241ce
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:39:59 2024 +0000

    Refactor gradio_demo.py and vision_encoder.py

commit 11619b7ca7c920fda02625f53a78c0a13c31c945
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:34:17 2024 +0000

    Refactor PhiForCausalLM class in modeling_phi.py

commit 2bf4eb998166a326b6a244f7a92f1a853a0e7817
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:25:19 2024 +0000

    Refactor PhiForCausalLM class in modeling_phi.py

commit 78f2edd4dd7ede9004b17829b834dc4634de7f59
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:23:59 2024 +0000

    Remove unused imports and variables

commit e6252a05dfad4eb265089147cce6a8cc9404e0bc
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:22:49 2024 +0000

    Refactor PhiModel forward method

commit 83362add27945409abdd1e1e37dfe30ff674202c
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:22:10 2024 +0000

    Refactor return statement in modeling_phi.py

commit aea6dcc4e19a7ccc4d793e410377d712e11e46e6
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:18:51 2024 +0000

    Refactor PhiPreTrainedModel's input handling

commit f08caef1b82c8c6805d1500fdf55c4b7690113d8
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:16:06 2024 +0000

    Add MHA and ParallelBlock classes

commit 6be42cd2682038e1497ed7c8da1fa22049ec6b33
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:14:02 2024 +0000

    Simplified CausalLMHead implementation

commit 863f13265e12ff50f361aea874e26083bb8afc7f
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:13:00 2024 +0000

    Refactor ParallelBlock class in modeling_phi.py

commit 2d3d197546240e14a9454a1765d10a46b6ad1472
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 09:01:25 2024 +0000

    Refactor ParallelBlock class in modeling_phi.py

commit 77e19808f4e0b1f9d2e8fb072f7c9257ad351206
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:58:30 2024 +0000

    Refactor inner_cross_attn function call in MHA class

commit f7e4b670fbf2decc26a7f1d9241e1beeaa45f7ff
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:57:40 2024 +0000

    Refactor MHA forward method

commit d3ed301d3a292d6f9bed26af0babcb4a0c296abd
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:55:53 2024 +0000

    Update MHA class with rotary embeddings

commit 0afdd4054a1d691b41c4c0e52addf332af4810c3
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:54:17 2024 +0000

    Refactor self-attention forward pass in MHA class

commit 1a8dde4b28eeae5c9dd62a00f1402a8d8bf399ff
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:53:19 2024 +0000

    Refactor MHA initialization and simplify RotaryEmbedding usage

commit 7ce1f8c45a021361e87e36cb1c1c9e28e3714439
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:48:16 2024 +0000

    Refactor _update_kv_cache function to improve memory usage

commit 70bd853cb7df4b49adc161a60d1ff7749601dbd7
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:47:30 2024 +0000

    Refactor _find_mha_dims function signature

commit 3b9598ed5a6a1849c2b2b7b413ff03ec64809237
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:42:05 2024 +0000

    Refactor forward method in CrossAttention class

commit 0607a683e8bc00812f72c37858fb1622d7310556
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:37:54 2024 +0000

    Add Flash Attention module

commit 30fc465d1a056510167c3be05b3f7455e2f6e9e3
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:32:16 2024 +0000

    Add Flash Attention module

commit 66427ecb22d3f2d2cab0ce7dc3ffeeb919fd99ca
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:29:05 2024 +0000

    Refactor SelfAttention class in modeling_phi.py

commit 107f9e317fcbd8f3313fa5e00f01241f9e308339
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:26:29 2024 +0000

    Refactor MLP module in modeling_phi.py

commit bcdfaa6f9821fe5b8ddd28bad792029e8baab709
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:23:05 2024 +0000

    Refactor forward method in RotaryEmbedding class

commit 3f0b043d55a157217fd4a9dd86284c79f7602ef0
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:16:58 2024 +0000

    Refactor RotaryEmbedding class to improve precision and performance

commit fc71d3338c3188301f087a38fd9e14319cc74f15
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:13:58 2024 +0000

    Update import statements and remove unused code

commit 1be11477b5c9ad1fbd01f023737ad3801acf756e
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:12:09 2024 +0000

    Refactor RotaryEmbedding class to use non-trainable buffers

commit 89dde7df1a9237d0838d1577fa0cba3d5172bd20
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:05:15 2024 +0000

    Refactor rotary embedding functions in modeling_phi.py

commit 085ee6b292bc21221cda4b36615d5fcfebb3e7df
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 08:02:29 2024 +0000

    Refactor rotary embedding functions

commit 025c8d454e15355ef7e1137c69d1c28305a6be63
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 07:59:09 2024 +0000

    Refactor rotary embedding calculation in modeling_phi.py

commit 873b39219c1cbb2906e17fc4e92ca8da66bf800e
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 07:58:12 2024 +0000

    Refactor _apply_rotary_emb_kv function to improve readability and performance

commit 32382c2eaa988e714fcfc3b5526890a946d9a776
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 07:54:45 2024 +0000

    Refactor rotary embedding function in modeling_phi.py

commit 3226f9f55c0c93ba7f0138bcf4532f1a687cb3f7
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 07:44:18 2024 +0000

    Refactor InferenceParams and Embedding classes

commit d5b825d3c92bd8422dfe6d266f9a3c5e1c7f4c4c
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 07:24:26 2024 +0000

    Refactor PhiConfig class in configuration_phi.py

commit 7a4d6c34fa23fd7878c03349e38200bb6fed0d06
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 07:16:25 2024 +0000

    Refactor text_model.py and vision_encoder.py

commit ddf4a06c7171c9ee0a345fbd77b5bbe9c3cf6487
Author: Markus Heimerl <149831926+markusheimerl@users.noreply.github.com>
Date:   Mon Jan 29 07:11:37 2024 +0000

    Refactor code and remove unused imports
2024-02-01 12:47:00 +02:00

4.6 KiB

🌔 moondream

a tiny vision language model that kicks ass and runs anywhere

moondream1

1.6B parameter model built using SigLIP, Phi-1.5 and the LLaVA training dataset. Weights are licensed under CC-BY-SA due to using the LLaVA dataset. Try it out on Hugging Face Spaces!

Benchmarks

Model Parameters VQAv2 GQA VizWiz TextVQA
LLaVA-1.5 13.3B 80.0 63.3 53.6 61.3
LLaVA-1.5 7.3B 78.5 62.0 50.0 58.2
MC-LLaVA-3B 3B 64.2 49.6 24.9 38.6
LLaVA-Phi 3B 71.4 - 35.9 48.6
moondream1 1.6B 74.3 56.3 30.3 39.8

Examples

Image Examples
What is the title of this book?
The Little Book of Deep Learning

What can you tell me about this book?
The book appears to be a white booklet titled "The Little Book of Deep Learning." It is held in a person's hand, and it seems to be a personal possession. The book's content focuses on the basics of deep learning, which is a field of artificial intelligence that uses neural networks to process and analyze data. It is likely that the book provides an introduction to the concepts and techniques involved in deep learning, making it accessible for beginners and helping them understand the fundamentals of this advanced machine learning approach.

Where is the person standing?
The person is standing on a balcony or a deck, which is located outside the house.
What type of food is the girl holding?
The girl is holding a large hamburger or burger, which is a type of sandwich made from ground meat, typically consisting of a beef patty, and is usually served between two slices of bread.

What color is the woman's hair?
The woman's hair is white.

What is the girl doing in the image?
The girl in the image is eating a hamburger.
What color is the train?
The train is red.

What is the bus doing in the image?
The bus is driving down a street, passing through an intersection, and traveling on a train track.

What kind of public transportation is in the image?
The image features a red trolley or commuter train on a city street, which is a form of public transportation.
What is the girl looking at?
The girl is looking at her reflection in the mirror while adjusting her uniform.

What color is the woman's hair?
The woman's hair is brown.

What is the woman doing in the mirror?
The woman is adjusting her hair in the mirror.
What might be the reason for the dog's aggressive behavior?
The dog's aggressive behavior, with its teeth bared and growling, could be due to several reasons. It is possible that the dog is feeling threatened, scared, or defensive in its current environment, such as a room with a person it doesn't know well or a situation that provokes it. Alternatively, the dog might be reacting to a perceived threat or discomfort from the person holding it. It is essential to assess the situation and the dog's body language to determine the exact cause of its aggressive behavior and respond accordingly to ensure the safety and well-being of both the dog and the person involved.

What kind of dog is in the picture?
The picture features a small dog, possibly a Chihuahua, with red eyes and a mean, hungry-looking expression.

What color is the dog?
The dog is black and white.

Usage

Clone this repository and install the dependencies:

pip install -r requirements.txt

Use the sample.py script to run the model on CPU:

python sample.py --image [IMAGE_PATH] --prompt [PROMPT]

When the --prompt argument is not provided, the script will allow you to ask questions interactively.

Gradio demo

Use the gradio_demo.py script to run the gradio app:

python gradio_demo.py

Limitations

  • The model may generate inaccurate statements.
  • It may struggle to adhere to intricate or nuanced instructions.
  • It is primarily designed to understand English. Informal English, slang, and non-English languages may not work well.
  • The model may not be free from societal biases. Users should be aware of this and exercise caution and critical thinking when using the model.
  • The model may generate offensive, inappropriate, or hurtful content if it is prompted to do so.