Instructions to use momergul/flamingo_test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use momergul/flamingo_test with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="momergul/flamingo_test", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("momergul/flamingo_test", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("momergul/flamingo_test", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use momergul/flamingo_test with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "momergul/flamingo_test" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "momergul/flamingo_test", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/momergul/flamingo_test
- SGLang
How to use momergul/flamingo_test with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "momergul/flamingo_test" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "momergul/flamingo_test", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "momergul/flamingo_test" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "momergul/flamingo_test", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use momergul/flamingo_test with Docker Model Runner:
docker model run hf.co/momergul/flamingo_test
Download utils.py from momergul/flamingo_test: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/momergul/flamingo_test/resolve/main/utils.py
- Command line
-
hf download hf://momergul/flamingo_test/utils.py
-
curl -L -o utils.py https://huggingface.co/momergul/flamingo_test/resolve/main/utils.py
1.23 kB
| import torch | |
| def exists(val): | |
| return val is not None | |
| # for controlling freezing during training of flamingo | |
| def set_module_requires_grad_(module, requires_grad): | |
| for param in module.parameters(): | |
| param.requires_grad = requires_grad | |
| def freeze_all_layers_(module): | |
| set_module_requires_grad_(module, False) | |
| def unfreeze_all_layers_(module): | |
| set_module_requires_grad_(module, True) | |
| def freeze_model_and_make_eval_(model): | |
| model.eval() | |
| freeze_all_layers_(model) | |
| def _make_att_wd_mask( | |
| input_ids_shape: torch.Size, | |
| dtype: torch.dtype, device: torch.device, | |
| past_key_values_length: int = 0, | |
| att_wd_size: int = 0, | |
| ): | |
| bsz, tgt_len = input_ids_shape | |
| mask = torch.full((tgt_len, tgt_len), torch.finfo(dtype).min, device=device) | |
| mask_cond = torch.arange(mask.size(-1), device=device) | |
| mask.masked_fill_( | |
| mask_cond > (mask_cond - att_wd_size).view(mask.size(-1), 1), 0) | |
| mask = mask.to(dtype) | |
| if past_key_values_length > 0: | |
| mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype, device=device), mask], dim=-1) | |
| return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len + past_key_values_length) | |