Instructions to use keras/smolvlm2_2.2b_instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasHub
How to use keras/smolvlm2_2.2b_instruct with KerasHub:
import keras_hub # Load CausalLM model (optional: use half precision for inference) causal_lm = keras_hub.models.CausalLM.from_preset("hf://keras/smolvlm2_2.2b_instruct", dtype="bfloat16") causal_lm.compile(sampler="greedy") # (optional) specify a sampler # Generate text causal_lm.generate("Keras: deep learning for", max_length=64)import keras_hub # Create a Backbone model unspecialized for any task backbone = keras_hub.models.Backbone.from_preset("hf://keras/smolvlm2_2.2b_instruct") - Keras
How to use keras/smolvlm2_2.2b_instruct with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://keras/smolvlm2_2.2b_instruct") - Notebooks
- Google Colab
- Kaggle
Download preprocessor.json from keras/smolvlm2_2.2b_instruct: direct link, hf CLI and curl.
- Browser
- Download file 6.07 kB
-
https://huggingface.co/keras/smolvlm2_2.2b_instruct/resolve/main/preprocessor.json
- Command line
-
hf download hf://keras/smolvlm2_2.2b_instruct/preprocessor.json
-
curl -L -o preprocessor.json https://huggingface.co/keras/smolvlm2_2.2b_instruct/resolve/main/preprocessor.json
6.07 kB
| { | |
| "module": "keras_hub.src.models.smolvlm2.smolvlm2_causal_lm_preprocessor", | |
| "class_name": "SmolVLM2CausalLMPreprocessor", | |
| "config": { | |
| "name": "smol_vlm2_causal_lm_preprocessor", | |
| "trainable": true, | |
| "dtype": { | |
| "module": "keras", | |
| "class_name": "DTypePolicy", | |
| "config": { | |
| "name": "float32" | |
| }, | |
| "registered_name": null | |
| }, | |
| "tokenizer": { | |
| "module": "keras_hub.src.models.smolvlm2.smolvlm2_tokenizer", | |
| "class_name": "SmolVLM2Tokenizer", | |
| "config": { | |
| "name": "smol_vlm2_tokenizer", | |
| "trainable": true, | |
| "dtype": { | |
| "module": "keras", | |
| "class_name": "DTypePolicy", | |
| "config": { | |
| "name": "int32" | |
| }, | |
| "registered_name": null | |
| }, | |
| "config_file": "tokenizer.json", | |
| "sequence_length": null, | |
| "add_prefix_space": false, | |
| "unsplittable_tokens": [ | |
| "<row_4_col_1>", | |
| "<row_2_col_3>", | |
| "<issue_start>", | |
| "<jupyter_start>", | |
| "<global-img>", | |
| "<row_3_col_6>", | |
| "<reponame>", | |
| "<row_4_col_6>", | |
| "<row_3_col_3>", | |
| "<row_6_col_4>", | |
| "<row_6_col_3>", | |
| "<gh_stars>", | |
| "<row_5_col_4>", | |
| "<row_2_col_6>", | |
| "<row_3_col_5>", | |
| "<jupyter_text>", | |
| "<row_5_col_2>", | |
| "<row_5_col_5>", | |
| "<row_6_col_6>", | |
| "<row_3_col_4>", | |
| "<row_5_col_6>", | |
| "<|endoftext|>", | |
| "<row_4_col_2>", | |
| "<fake_token_around_image>", | |
| "<|im_end|>", | |
| "<row_1_col_2>", | |
| "<|im_start|>", | |
| "<jupyter_output>", | |
| "<row_3_col_2>", | |
| "<row_6_col_1>", | |
| "<row_2_col_1>", | |
| "<row_2_col_5>", | |
| "<image>", | |
| "<row_5_col_3>", | |
| "<row_2_col_4>", | |
| "<repo_name>", | |
| "<filename>", | |
| "<issue_closed>", | |
| "<jupyter_script>", | |
| "<row_4_col_4>", | |
| "<jupyter_code>", | |
| "<row_2_col_2>", | |
| "<row_6_col_2>", | |
| "<row_1_col_5>", | |
| "<row_1_col_3>", | |
| "<row_1_col_6>", | |
| "<row_3_col_1>", | |
| "<file_sep>", | |
| "<row_4_col_5>", | |
| "<row_1_col_4>", | |
| "<row_5_col_1>", | |
| "<empty_output>", | |
| "<issue_comment>", | |
| "<row_4_col_3>", | |
| "<row_1_col_1>", | |
| "<end_of_utterance>", | |
| "<row_6_col_5>" | |
| ] | |
| }, | |
| "registered_name": "keras_hub>SmolVLM2Tokenizer" | |
| }, | |
| "image_converter": { | |
| "module": "keras_hub.src.models.smolvlm2.smolvlm2_image_converter", | |
| "class_name": "SmolVLM2ImageConverter", | |
| "config": { | |
| "name": "smol_vlm2_image_converter", | |
| "trainable": true, | |
| "dtype": { | |
| "module": "keras", | |
| "class_name": "DTypePolicy", | |
| "config": { | |
| "name": "float32" | |
| }, | |
| "registered_name": null | |
| }, | |
| "image_size": null, | |
| "scale": [ | |
| 0.00784313725490196, | |
| 0.00784313725490196, | |
| 0.00784313725490196 | |
| ], | |
| "offset": [ | |
| -1.0, | |
| -1.0, | |
| -1.0 | |
| ], | |
| "interpolation": "lanczos3", | |
| "antialias": true, | |
| "crop_to_aspect_ratio": true, | |
| "pad_to_aspect_ratio": false, | |
| "bounding_box_format": "yxyx", | |
| "max_image_size": 384, | |
| "size": 1536, | |
| "do_image_splitting": true | |
| }, | |
| "registered_name": "keras_hub>SmolVLM2ImageConverter" | |
| }, | |
| "video_converter": { | |
| "module": "keras_hub.src.models.smolvlm2.smolvlm2_video_converter", | |
| "class_name": "SmolVLM2VideoConverter", | |
| "config": { | |
| "name": "smol_vlm2_video_converter", | |
| "trainable": true, | |
| "dtype": { | |
| "module": "keras", | |
| "class_name": "DTypePolicy", | |
| "config": { | |
| "name": "float32" | |
| }, | |
| "registered_name": null | |
| }, | |
| "image_size": null, | |
| "scale": [ | |
| 0.00784313725490196, | |
| 0.00784313725490196, | |
| 0.00784313725490196 | |
| ], | |
| "offset": [ | |
| -1.0, | |
| -1.0, | |
| -1.0 | |
| ], | |
| "max_image_size": 384, | |
| "size": 1536, | |
| "num_frames": 64, | |
| "fps": 1, | |
| "interpolation": "lanczos3", | |
| "antialias": true | |
| }, | |
| "registered_name": "keras_hub>SmolVLM2VideoConverter" | |
| }, | |
| "config_file": "preprocessor.json", | |
| "sequence_length": 1024, | |
| "add_start_token": false, | |
| "add_end_token": true, | |
| "image_seq_len": 81 | |
| }, | |
| "registered_name": "keras_hub>SmolVLM2CausalLMPreprocessor" | |
| } |