Instructions to use tiny-random/minicpm-ocr-jev with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/minicpm-ocr-jev with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/minicpm-ocr-jev") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForSequenceClassification processor = AutoProcessor.from_pretrained("tiny-random/minicpm-ocr-jev") model = AutoModelForSequenceClassification.from_pretrained("tiny-random/minicpm-ocr-jev", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/minicpm-ocr-jev with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/minicpm-ocr-jev" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/minicpm-ocr-jev", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/tiny-random/minicpm-ocr-jev
- SGLang
How to use tiny-random/minicpm-ocr-jev 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 "tiny-random/minicpm-ocr-jev" \ --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": "tiny-random/minicpm-ocr-jev", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "tiny-random/minicpm-ocr-jev" \ --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": "tiny-random/minicpm-ocr-jev", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use tiny-random/minicpm-ocr-jev with Docker Model Runner:
docker model run hf.co/tiny-random/minicpm-ocr-jev
Download .meta/create_model.py from tiny-random/minicpm-ocr-jev: direct link, hf CLI and curl.
- Browser
- Download file 3.26 kB
-
https://huggingface.co/tiny-random/minicpm-ocr-jev/resolve/main/.meta/create_model.py
- Command line
-
hf download hf://tiny-random/minicpm-ocr-jev/.meta/create_model.py
-
curl -L -o create_model.py https://huggingface.co/tiny-random/minicpm-ocr-jev/resolve/main/.meta/create_model.py
3.26 kB
| def create_model(source_model_id: str, source_revision: str, save_folder: str) -> str: | |
| import json | |
| from pathlib import Path | |
| import torch | |
| from huggingface_hub import hf_hub_download | |
| from safetensors.torch import save_file | |
| from transformers import AutoConfig, AutoModelForSequenceClassification, set_seed | |
| folder = Path(save_folder) | |
| folder.mkdir(parents=True, exist_ok=True) | |
| config = json.loads( | |
| Path(hf_hub_download(source_model_id, "config.json", revision=source_revision)).read_text(encoding="utf-8") | |
| ) | |
| text = config["text_config"] | |
| text.update( | |
| hidden_size=16, | |
| intermediate_size=32, | |
| head_dim=256, | |
| num_hidden_layers=8, | |
| num_attention_heads=8, | |
| num_key_value_heads=2, | |
| linear_key_head_dim=128, | |
| linear_value_head_dim=128, | |
| linear_num_key_heads=16, | |
| linear_num_value_heads=16, | |
| layer_types=["linear_attention", "linear_attention", "linear_attention", "full_attention"] * 2, | |
| ) | |
| config["vision_config"].update( | |
| hidden_size=128, | |
| intermediate_size=256, | |
| depth=4, | |
| num_heads=4, | |
| out_hidden_size=16, | |
| ) | |
| config["hidden_size"] = 16 | |
| config["num_labels"] = 2 | |
| config["architectures"] = ["Qwen3_5ForSequenceClassification"] | |
| config["problem_type"] = "single_label_classification" | |
| (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8") | |
| for name in ( | |
| "chat_template.jinja", | |
| "generation_config.json", | |
| "preprocessor_config.json", | |
| "processor_config.json", | |
| "tokenizer.json", | |
| "tokenizer_config.json", | |
| ): | |
| (folder / name).write_bytes(Path(hf_hub_download(source_model_id, name, revision=source_revision)).read_bytes()) | |
| previous_dtype = torch.get_default_dtype() | |
| try: | |
| torch.set_default_dtype(torch.bfloat16) | |
| set_seed(42) | |
| model = AutoModelForSequenceClassification.from_config(AutoConfig.from_pretrained(folder)) | |
| with torch.no_grad(): | |
| for name, parameter in sorted(model.named_parameters()): | |
| if name.endswith("A_log"): | |
| parameter.zero_() | |
| elif name.endswith("dt_bias"): | |
| parameter.fill_(1) | |
| elif name.endswith("weight") and "norm" in name: | |
| parameter.fill_(1) | |
| elif name.endswith("bias"): | |
| parameter.zero_() | |
| else: | |
| parameter.normal_(mean=0.0, std=0.02) | |
| state = {name: value.detach().cpu().contiguous() for name, value in model.state_dict().items()} | |
| save_file(state, folder / "model.safetensors", metadata={"format": "pt"}) | |
| finally: | |
| torch.set_default_dtype(previous_dtype) | |
| (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8") | |
| (folder / "generation_config.json").write_bytes( | |
| Path(hf_hub_download(source_model_id, "generation_config.json", revision=source_revision)).read_bytes() | |
| ) | |
| return str(model) | |
| create_model( | |
| source_model_id="openbmb/MiniCPM-OCR-Jev", | |
| source_revision="bdb03f86182a2824d2632d129c719cdf780502e2", | |
| save_folder="/tmp/minicpm-ocr-jev", | |
| ) | |