Your image is almost there!
Omost is a project to convert LLM's coding capability to image generation (or more accurately, image composing) capability.
The name Omost (pronunciation: almost) has two meanings: 1) everytime after you use Omost, your image is almost there; 2) the O mean "omni" (multi-modal) and most means we want to get the most out of it.
Omost provides LLMs models that will write codes to compose image visual contents with Omost's virtual Canvas agent. This Canvas can be rendered by specific implementations of image generators to actually generate images.
Currently, we provide 3 pretrained LLM models based on variations of Llama3 and Phi3 (see also the model notes at the end of this page).
All models are trained with mixed data of (1) ground-truth annotations of several datasets including Open-Images, (2) extracted data by automatically annotating images, (3) reinforcement from DPO (Direct Preference Optimization, "whether the codes can be compiled by python 3.10 or not" as a direct preference), and (4) a small amount of tuning data from OpenAI GPT4o's multi-modal capability.
You can just use the official HuggingFace space.
Or, you can use the below deployment (requires 8GB Nvidia VRAM):
git clone https://github.com/lllyasviel/Omost.git
cd Omost
conda create -n omost python=3.10
conda activate omost
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt
python gradio_app.py(Note that quant LLM requires bitsandbytes - some 9XX or 10XX or 20XX GPUs may have trouble in running it. If that happens, just use our official huggingface space.)
(All with random seed 12345)
a ragged man wearing a tattered jacket in the nineteenth century:
the greatest escape after the apocalypse, the hope of all humanity:
jurassic dinosaur battle:
the supreme ruler with endless magic on a gothic throne, with undead armies kneeling:
a funny cartoon batman fights joker:
(Below is a raw transcript from default model, with random seed 123456)
(If the GitHub's code block rendering is causing troubles to reading long lines, click here to read raw texts.)
generate an image of the fierce battle of warriors and the dragon
…change the dragon to a dinosaur
…(User can click the render button to actually render the image from any of those Canvas instances.)
All Omost LLMs are trained to obey the following symbols
…During training, the above symbols are associated with specific concepts and use cases related to image generation.
The design is to make those codes easy to learn for LLMs, but also easy to handle for diffusion models.
Lets breakdown each part:
They set descriptions to images. The meanings of the parameters are same for them, with add_local_description having more fields than set_global_description.
The set_global_description annotate entire image, while add_local_description annotates a part of image.
Let us introduce a concept called "sub-prompt". If a prompt is less than 75 tokens, and is self-supported to describe a thing without relying on other prompts, we call it a "sub-prompt".
The description is a sub-prompt, and the detailed_descriptions is a list of sub-prompts.
Note that each sub-prompt is strictly less than 75 tokens (and typically less than 40 tokens), you can safely encode them with any clip without worrying the truncation position affecting the semantics.
The design of sub-prompt also allows more satisfying text encoding based on greedy merge. For example, if you have
sub-prompt A: 25 tokens
sub-prompt B: 35 tokens
sub-prompt C: 5 tokens
sub-prompt D: 60 tokens
sub-prompt E: 15 tokens
sub-prompt F: 25 tokensand since every sub-prompt is promised to be self-supported to describe a thing independently, we can use greedy method to merge them to bags like
bag 1 {A, B, C} : 65 tokens
bag 2 {D} : 60 tokens
bag 1 {E, F} : 40 tokenswhere each bag is less than 75 tokens and can be encoded by any clip in one pass (and then concat them).
Encoding texts in this way will make sure that text-encoder will never make semantic truncation mistakes.
One may ask - if all sub-prompts are less than 75 tokens with independent semantics, why not just encode them without merge and then concat? This is mainly because we want the text embedding to be more coherent. For example, lets say sub-prompt A is "a man" while sub-prompt B is "handsome, professional", then merging them before encoding will give you a more mixed text embedding concept with coherent features of a handsome professional man.
All Omost LLMs are trained to give strictly well-defined sub-prompts. You can make use of these definitions to design lossless text encoding methods.
The three parameters defines a bounding box. Note that they must obey
…First we divide a canvas into 3*3=9 locations:
Then we further divide each location to 3*3 offsets, resulting in 9*9=81 positions:
Using these positions as centers, we further define 9 types of bounding boxes:
We can see that this method allows 9*9*9=729 different bounding boxes, covering almost all common possible locations of an object in the image.
One may argue that why this is necessary - why not just let the LLMs to learn pixel index or x, y coordinates - and should that be much more accurate? Below is several of my notes:
The distance_to_viewer can be viewed as relative depth. Note that this value's absolute number is not reliable at all (because opensource LLMs are not very good at producing image-space numbers) and it should only be used in sorting elements into background-to-foreground layers.
You can always use distance_to_viewer to sort all local elements before rendering them using a diffusion model. The global description can be always viewed as the most far away background layer.
The HTML_web_color_name is one of these:
…By combining distance_to_viewer and HTML_web_color_name, you can draw a very coarse image of the composition. For example, if the LLM works well, "a green bottle in front of a red bottle on a wood table in a dark room" should make it possible for you to compute an image like:
You can use this image as an initial latent and use denoise strength like 0.95 to 0.99 to generate the image.
Or if you do not like this and still prefer to let diffusion models to generate from zero-mean (even when you know that most diffusion models have tsnr problems), you can ignore this image and or just use this image as a debugger.
Besides, the layer sorting can also be useful in some very special attention formulation - we will discuss this later.
The tags is designed as a possible replacement for the description since many diffusion models prefer tags. If used with anime models, one may hard code some logics to replace all "girl" to "1girl". If used with Pony then probably always hard code adding "score_9, score_8 ..." to this.
The atmosphere and style and quality_meta are some experimental parameters without very specific use cases. Current we can just treat them as sub-prompts and involve them in the greedy merge of sub-prompt bags. This in my experiments will improve the atmosphere and quality a bit.
In this repo, we provide a baseline render for Omost LLMs based on attention manipulation.
As of 2024, if we want to achieve a region guided diffusion system, some possible options are:
y=softmax(q@k)@v, then one can achieve attention decomposition like y=mask_A * softmax(q@k_A)@v_A + mask_B * softmax(q@k_B)@v_B where mask_A, k_A, v_A are masks, k, v for region A; mask_B, k_B, v_B are masks, k, v for region B. This method usually yields image quality a bit better than (1) and some people call it Attention Couple or Region Prompter Attention Mode. But this method has a consideration: the mask only makes regional attention numerically possible, but it does not force the UNet to really attend its activations in those regions. That is to say, the attention is indeed masked, but there is no promise that the attention softmax will really be activated in the masked area, and there is also no promise that the attention softmax will never be activated outside the masked area.y=softmax(modify(q@k))@v where modify() is a complicated non-linear function with many normalizations and tricks to change the score's distributions. This method goes beyond a simple masked attention to really make sure that those layers get wanted activations. A typical example is Dense Diffusion.Will we get an updated Omost based on the newest image generation models like qwen-image, z-image, or flux klein?
运行python gradio_app.py时报错
Error API
ing cached gradio-4.31.5-py3-none-any.whl.metadata (15 kB) ERROR: Could not find a version that satisfies the requirement bitsandbytes==0.43.1 (from versions: 0.31.8, 0.32.0, 0.32.1, 0.32.2, 0.32.3, 0.33.0, 0.33.1, 0.34.0, 0.35.0, 0.35.1, 0.35.2, 0.35.3, 0.35.4, 0.36.0, 0.36.0.post1, 0.36.0.post2, 0.37.0, 0.37.1, 0.37.2, 0.38.0, 0.38.0.post1, 0.38.0.post2, 0.38.1, 0.39.0, 0.39.1, 0.40.0, 0.40.0.post1, 0.40.0.post2, 0.40.0.post3, 0.40.0.post4, 0.40.1, 0.40.1.post1, 0.40.2, 0.41.0, 0.41.1, 0.41.2, 0.41.2.post1, 0.41.2.post2, 0.41.3, 0.41.3.post1, 0.41.3.post2, 0.42.0) ERROR: No matching distribution found for bitsandbytes==0.43.1
Pip install -r requirements.txt ...
There is no image generation button on the left side, how to solve this ah, have you ever encountered!
[Bug] LLM halucinates and repeats same sequence nonstop
ImportError: cannot import name 'EncoderDecoderCache' from 'transformers'
Using vLLM to deploy LLM as an API to accelerate inference
Last assistant response is not valid canvas: expected string or bytes-like object