Text Generation
Transformers
Safetensors
English
h2ovl_chat
feature-extraction
gpt
llm
multimodal large language model
ocr
conversational
custom_code
Instructions to use h2oai/h2ovl-mississippi-800m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use h2oai/h2ovl-mississippi-800m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="h2oai/h2ovl-mississippi-800m", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("h2oai/h2ovl-mississippi-800m", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use h2oai/h2ovl-mississippi-800m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "h2oai/h2ovl-mississippi-800m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "h2oai/h2ovl-mississippi-800m", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/h2oai/h2ovl-mississippi-800m
- SGLang
How to use h2oai/h2ovl-mississippi-800m 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 "h2oai/h2ovl-mississippi-800m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "h2oai/h2ovl-mississippi-800m", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "h2oai/h2ovl-mississippi-800m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "h2oai/h2ovl-mississippi-800m", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use h2oai/h2ovl-mississippi-800m with Docker Model Runner:
docker model run hf.co/h2oai/h2ovl-mississippi-800m
fix: compute stochastic-depth rates in pure Python for transformers 5.x meta-device init
#4
by brandenh2oai - opened
- configuration_h2ovl_chat.py +25 -1
- modeling_intern_vit.py +20 -3
- modelling_h2ovl_chat.py +8 -1
configuration_h2ovl_chat.py
CHANGED
|
@@ -46,7 +46,31 @@ class H2OVLChatConfig(PretrainedConfig):
|
|
| 46 |
self.llm_config = CONFIG_MAPPING[llm_config["model_type"]](**llm_config)
|
| 47 |
else:
|
| 48 |
self.llm_config = AutoConfig.from_pretrained(llm_config["_name_or_path"], trust_remote_code=True)
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
self.use_backbone_lora = use_backbone_lora
|
| 52 |
self.use_llm_lora = use_llm_lora
|
|
|
|
| 46 |
self.llm_config = CONFIG_MAPPING[llm_config["model_type"]](**llm_config)
|
| 47 |
else:
|
| 48 |
self.llm_config = AutoConfig.from_pretrained(llm_config["_name_or_path"], trust_remote_code=True)
|
| 49 |
+
# transformers>=5 derives rope_parameters in the sub-config __init__;
|
| 50 |
+
# re-applying the legacy rope_theta/rope_scaling (or a stale
|
| 51 |
+
# rope_parameters) via update() would reset it to None. Filter those keys
|
| 52 |
+
# so the v5-derived rope config is preserved.
|
| 53 |
+
self.llm_config.update({
|
| 54 |
+
k: v for k, v in llm_config.items()
|
| 55 |
+
if k not in ("rope_parameters", "rope_theta", "rope_scaling")
|
| 56 |
+
})
|
| 57 |
+
|
| 58 |
+
# transformers>=5 no longer permits generation-control parameters to live
|
| 59 |
+
# on the model config (they must be on generation_config). This llm_config
|
| 60 |
+
# was saved under transformers 4.x with legacy generation defaults baked
|
| 61 |
+
# in; v5 dropped these attrs from PretrainedConfig, so even their old
|
| 62 |
+
# defaults now read as "non-default" and language_model.generate() raises
|
| 63 |
+
# "This strategy to control generation is not supported anymore". The model
|
| 64 |
+
# ships a proper generation_config.json, so strip the stale attrs here.
|
| 65 |
+
for _gen_attr in (
|
| 66 |
+
"length_penalty",
|
| 67 |
+
"encoder_no_repeat_ngram_size",
|
| 68 |
+
"output_scores",
|
| 69 |
+
"return_dict_in_generate",
|
| 70 |
+
"remove_invalid_values",
|
| 71 |
+
):
|
| 72 |
+
if hasattr(self.llm_config, _gen_attr):
|
| 73 |
+
delattr(self.llm_config, _gen_attr)
|
| 74 |
|
| 75 |
self.use_backbone_lora = use_backbone_lora
|
| 76 |
self.use_llm_lora = use_llm_lora
|
modeling_intern_vit.py
CHANGED
|
@@ -312,7 +312,20 @@ class InternVisionEncoder(nn.Module):
|
|
| 312 |
super().__init__()
|
| 313 |
self.config = config
|
| 314 |
# stochastic depth decay rule
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
self.layers = nn.ModuleList([
|
| 317 |
InternVisionEncoderLayer(config, dpr[idx]) for idx in range(config.num_hidden_layers)])
|
| 318 |
self.gradient_checkpointing = True
|
|
@@ -336,7 +349,7 @@ class InternVisionEncoder(nn.Module):
|
|
| 336 |
output_hidden_states = (
|
| 337 |
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 338 |
)
|
| 339 |
-
return_dict = return_dict if return_dict is not None else self.config.
|
| 340 |
|
| 341 |
encoder_states = () if output_hidden_states else None
|
| 342 |
hidden_states = inputs_embeds
|
|
@@ -366,7 +379,11 @@ class InternVisionEncoder(nn.Module):
|
|
| 366 |
|
| 367 |
class InternVisionModel(PreTrainedModel):
|
| 368 |
main_input_name = 'pixel_values'
|
|
|
|
|
|
|
|
|
|
| 369 |
_supports_flash_attn_2 = True
|
|
|
|
| 370 |
config_class = InternVisionConfig
|
| 371 |
_no_split_modules = ['InternVisionEncoderLayer']
|
| 372 |
|
|
@@ -402,7 +419,7 @@ class InternVisionModel(PreTrainedModel):
|
|
| 402 |
output_hidden_states = (
|
| 403 |
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 404 |
)
|
| 405 |
-
return_dict = return_dict if return_dict is not None else self.config.
|
| 406 |
|
| 407 |
if pixel_values is None and pixel_embeds is None:
|
| 408 |
raise ValueError('You have to specify pixel_values or pixel_embeds')
|
|
|
|
| 312 |
super().__init__()
|
| 313 |
self.config = config
|
| 314 |
# stochastic depth decay rule
|
| 315 |
+
# Computed in pure Python (equivalent to
|
| 316 |
+
# `torch.linspace(0, config.drop_path_rate, config.num_hidden_layers)`)
|
| 317 |
+
# so it works under transformers 5.x meta-device init: model __init__ now
|
| 318 |
+
# runs inside a `with torch.device("meta")` context, under which
|
| 319 |
+
# torch.linspace() yields a meta tensor and `.item()` raises
|
| 320 |
+
# "Tensor.item() cannot be called on meta tensors".
|
| 321 |
+
num_layers = config.num_hidden_layers
|
| 322 |
+
if num_layers > 1:
|
| 323 |
+
dpr = [
|
| 324 |
+
config.drop_path_rate * i / (num_layers - 1)
|
| 325 |
+
for i in range(num_layers)
|
| 326 |
+
]
|
| 327 |
+
else:
|
| 328 |
+
dpr = [0.0] * num_layers
|
| 329 |
self.layers = nn.ModuleList([
|
| 330 |
InternVisionEncoderLayer(config, dpr[idx]) for idx in range(config.num_hidden_layers)])
|
| 331 |
self.gradient_checkpointing = True
|
|
|
|
| 349 |
output_hidden_states = (
|
| 350 |
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 351 |
)
|
| 352 |
+
return_dict = return_dict if return_dict is not None else self.config.return_dict
|
| 353 |
|
| 354 |
encoder_states = () if output_hidden_states else None
|
| 355 |
hidden_states = inputs_embeds
|
|
|
|
| 379 |
|
| 380 |
class InternVisionModel(PreTrainedModel):
|
| 381 |
main_input_name = 'pixel_values'
|
| 382 |
+
# transformers>=5 checks _supports_flash_attn; transformers<5 checks
|
| 383 |
+
# _supports_flash_attn_2. Set both so flash-attention support is advertised
|
| 384 |
+
# on either version (the 5.x path treats _supports_flash_attn_2 as a fallback).
|
| 385 |
_supports_flash_attn_2 = True
|
| 386 |
+
_supports_flash_attn = True
|
| 387 |
config_class = InternVisionConfig
|
| 388 |
_no_split_modules = ['InternVisionEncoderLayer']
|
| 389 |
|
|
|
|
| 419 |
output_hidden_states = (
|
| 420 |
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 421 |
)
|
| 422 |
+
return_dict = return_dict if return_dict is not None else self.config.return_dict
|
| 423 |
|
| 424 |
if pixel_values is None and pixel_embeds is None:
|
| 425 |
raise ValueError('You have to specify pixel_values or pixel_embeds')
|
modelling_h2ovl_chat.py
CHANGED
|
@@ -29,7 +29,11 @@ def version_cmp(v1, v2, op='eq'):
|
|
| 29 |
class H2OVLChatModel(PreTrainedModel):
|
| 30 |
config_class = H2OVLChatConfig
|
| 31 |
main_input_name = 'pixel_values'
|
|
|
|
|
|
|
|
|
|
| 32 |
_supports_flash_attn_2 = True
|
|
|
|
| 33 |
|
| 34 |
def __init__(self, config: H2OVLChatConfig, vision_model=None, language_model=None):
|
| 35 |
super().__init__(config)
|
|
@@ -80,6 +84,9 @@ class H2OVLChatModel(PreTrainedModel):
|
|
| 80 |
if config.use_llm_lora:
|
| 81 |
self.wrap_llm_lora(r=config.use_llm_lora, lora_alpha=2 * config.use_llm_lora)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
| 83 |
def wrap_backbone_lora(self, r=128, lora_alpha=256, lora_dropout=0.05):
|
| 84 |
lora_config = LoraConfig(
|
| 85 |
r=r,
|
|
@@ -126,7 +133,7 @@ class H2OVLChatModel(PreTrainedModel):
|
|
| 126 |
output_hidden_states: Optional[bool] = None,
|
| 127 |
return_dict: Optional[bool] = None,
|
| 128 |
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 129 |
-
return_dict = return_dict if return_dict is not None else self.config.
|
| 130 |
|
| 131 |
image_flags = image_flags.squeeze(-1)
|
| 132 |
input_embeds = self.language_model.get_input_embeddings()(input_ids).clone()
|
|
|
|
| 29 |
class H2OVLChatModel(PreTrainedModel):
|
| 30 |
config_class = H2OVLChatConfig
|
| 31 |
main_input_name = 'pixel_values'
|
| 32 |
+
# transformers>=5 checks _supports_flash_attn; transformers<5 checks
|
| 33 |
+
# _supports_flash_attn_2. Set both so flash-attention support is advertised
|
| 34 |
+
# on either version (the 5.x path treats _supports_flash_attn_2 as a fallback).
|
| 35 |
_supports_flash_attn_2 = True
|
| 36 |
+
_supports_flash_attn = True
|
| 37 |
|
| 38 |
def __init__(self, config: H2OVLChatConfig, vision_model=None, language_model=None):
|
| 39 |
super().__init__(config)
|
|
|
|
| 84 |
if config.use_llm_lora:
|
| 85 |
self.wrap_llm_lora(r=config.use_llm_lora, lora_alpha=2 * config.use_llm_lora)
|
| 86 |
|
| 87 |
+
# transformers>=5 populates all_tied_weights_keys during post_init().
|
| 88 |
+
self.post_init()
|
| 89 |
+
|
| 90 |
def wrap_backbone_lora(self, r=128, lora_alpha=256, lora_dropout=0.05):
|
| 91 |
lora_config = LoraConfig(
|
| 92 |
r=r,
|
|
|
|
| 133 |
output_hidden_states: Optional[bool] = None,
|
| 134 |
return_dict: Optional[bool] = None,
|
| 135 |
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 136 |
+
return_dict = return_dict if return_dict is not None else self.config.return_dict
|
| 137 |
|
| 138 |
image_flags = image_flags.squeeze(-1)
|
| 139 |
input_embeds = self.language_model.get_input_embeddings()(input_ids).clone()
|