Instructions to use OzzyGT/Kimodo_SOMA_Modular with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use OzzyGT/Kimodo_SOMA_Modular with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("OzzyGT/Kimodo_SOMA_Modular", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download prompt_utils.py from OzzyGT/Kimodo_SOMA_Modular: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/OzzyGT/Kimodo_SOMA_Modular/resolve/main/prompt_utils.py
- Command line
-
hf download hf://OzzyGT/Kimodo_SOMA_Modular/prompt_utils.py
-
curl -L -o prompt_utils.py https://huggingface.co/OzzyGT/Kimodo_SOMA_Modular/resolve/main/prompt_utils.py
1.13 kB
| import torch | |
| def tokenize_prompt(tokenizer, prompt, max_length=512): | |
| token_count = len(tokenizer(prompt, add_special_tokens=False, truncation=True, max_length=max_length)["input_ids"]) | |
| while token_count > 400: | |
| prompt = " ".join(prompt.split()[: int(len(prompt.split()) * 400 / token_count)]) | |
| token_count = len( | |
| tokenizer(prompt, add_special_tokens=False, truncation=True, max_length=max_length)["input_ids"] | |
| ) | |
| formatted = "<|start_header_id|>user<|end_header_id|>\n\n" + prompt.strip() + "<|eot_id|>" | |
| inputs = tokenizer([formatted], return_tensors="pt", padding=True, truncation=True, max_length=max_length) | |
| # LLM2Vec excludes the instruction prefix, retaining the prompt and trailing end-of-turn token. | |
| suffix = tokenizer( | |
| [prompt.strip() + "<|eot_id|>"], | |
| return_tensors="pt", | |
| truncation=True, | |
| max_length=max_length, | |
| add_special_tokens=False, | |
| ) | |
| pooling_mask = torch.zeros_like(inputs["attention_mask"]) | |
| pooling_mask[:, -suffix["input_ids"].shape[1] :] = 1 | |
| inputs["pooling_mask"] = pooling_mask | |
| return inputs | |