Run this model with HF Jobs
Run tiny-random/minicpm4 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/tiny-random/minicpm4. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/tiny-random/minicpm4 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/tiny-random/minicpm4. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/tiny-random/minicpm4. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use tiny-random/minicpm4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/minicpm4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiny-random/minicpm4", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("tiny-random/minicpm4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/minicpm4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/minicpm4" # 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/minicpm4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tiny-random/minicpm4
- SGLang
How to use tiny-random/minicpm4 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/minicpm4" \ --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/minicpm4", "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 "tiny-random/minicpm4" \ --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/minicpm4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tiny-random/minicpm4 with Docker Model Runner:
docker model run hf.co/tiny-random/minicpm4
Upload folder using huggingface_hub
Browse filesFiles changed (9)
- README.mdAdded+123
- added_tokens.jsonAdded+10
- config.jsonAdded+81
- generation_config.jsonAdded+13
- model.safetensorsAdded+3
- special_tokens_map.jsonAdded+33
- tokenizer.jsonAdded
- tokenizer.modelAdded+3
- tokenizer_config.jsonAdded+118
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123---library_name: transformerspipeline_tag: text-generationinference: truewidget: - text: Hello! example_title: Hello world group: Python---
This tiny model is for debugging. It is randomly initialized with the config adapted from [openbmb/MiniCPM4-8B](https://huggingface.co/openbmb/MiniCPM4-8B).
### Example usage:
```pythonimport torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "tiny-random/minicpm4"
device = "cuda"tokenizer = AutoTokenizer.from_pretrained(model_id)model = AutoModelForCausalLM.from_pretrained( model_id, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)
# User can directly use the chat interface# responds, history = model.chat(tokenizer, "Write an article about Artificial Intelligence.", temperature=0.7, top_p=0.7)# print(responds)
# User can also use the generate interfacemessages = [ {"role": "user", "content": "Write an article about Artificial Intelligence."},]prompt_text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True,)model_inputs = tokenizer([prompt_text], return_tensors="pt").to(device)
model_outputs = model.generate( **model_inputs, max_new_tokens=32, top_p=0.7, temperature=0.7)output_token_ids = [ model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs['input_ids']))]
responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]print(responses)```
### Codes to create this repo:
```pythonimport jsonfrom pathlib import Path
import torch
import acceleratefrom huggingface_hub import hf_hub_downloadfrom transformers import ( AutoConfig, AutoModelForCausalLM, AutoTokenizer, GenerationConfig, set_seed,)
source_model_id = "openbmb/MiniCPM4-8B"save_folder = "/tmp/tiny-random/minicpm4"
processor = AutoTokenizer.from_pretrained(source_model_id)processor.save_pretrained(save_folder)
with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f: config_json = json.load(f)config_json["hidden_size"] = 64config_json['intermediate_size'] = 128config_json['num_attention_heads'] = 2config_json['num_key_value_heads'] = 1config_json['dim_model_base'] = 32config_json['num_hidden_layers'] = 2config_json['tie_word_embeddings'] = Truefor k, v in config_json['auto_map'].items(): config_json['auto_map'][k] = f'{source_model_id}--{v}'automap = config_json['auto_map']factor = config_json['rope_scaling']['long_factor']config_json['rope_scaling']['long_factor'] = factor[:16]config_json['rope_scaling']['short_factor'] = factor[:16]with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f: json.dump(config_json, f, indent=2)
config = AutoConfig.from_pretrained( save_folder, trust_remote_code=True,)print(config)torch.set_default_dtype(torch.bfloat16)model = AutoModelForCausalLM.from_config(config, trust_remote_code=True)torch.set_default_dtype(torch.float32)model.generation_config = GenerationConfig.from_pretrained( source_model_id, trust_remote_code=True,)set_seed(42)with torch.no_grad(): for name, p in sorted(model.named_parameters()): torch.nn.init.normal_(p, 0, 0.2) print(name, p.shape) passmodel.save_pretrained(save_folder)with open(f"{save_folder}/config.json", "r", encoding='utf-8') as f: config_json = json.load(f) config_json['auto_map'] = automapwith open(f"{save_folder}/config.json", "w", encoding='utf-8') as f: json.dump(config_json, f, indent=2)for python_file in Path(save_folder).glob('*.py'): python_file.unlink()```12345678910{ "<|execute_end|>": 73444, "<|execute_start|>": 73443, "<|fim_middle|>": 73446, "<|fim_prefix|>": 73445, "<|fim_suffix|>": 73447, "<|im_end|>": 73440, "<|im_start|>": 73441, "<|tool_call|>": 73442}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081{ "architectures": [ "MiniCPMForCausalLM" ], "attention_bias": false, "attention_dropout": 0.0, "auto_map": { "AutoConfig": "openbmb/MiniCPM4-8B--configuration_minicpm.MiniCPMConfig", "AutoModel": "openbmb/MiniCPM4-8B--modeling_minicpm.MiniCPMModel", "AutoModelForCausalLM": "openbmb/MiniCPM4-8B--modeling_minicpm.MiniCPMForCausalLM", "AutoModelForSeq2SeqLM": "openbmb/MiniCPM4-8B--modeling_minicpm.MiniCPMForCausalLM", "AutoModelForSequenceClassification": "openbmb/MiniCPM4-8B--modeling_minicpm.MiniCPMForSequenceClassification" }, "bos_token_id": 1, "dim_model_base": 32, "eos_token_id": [ 2, 73440 ], "hidden_act": "silu", "hidden_size": 64, "initializer_range": 0.1, "intermediate_size": 128, "max_position_embeddings": 32768, "model_type": "minicpm", "mup_denominator": 32, "num_attention_heads": 2, "num_hidden_layers": 2, "num_key_value_heads": 1, "pad_token_id": 2, "pretraining_tp": 1, "rms_norm_eps": 1e-06, "rope_scaling": { "long_factor": [ 0.9977997200264581, 1.014658295992452, 1.0349680404997148, 1.059429246056193, 1.0888815016813513, 1.1243301355211495, 1.166977103606075, 1.2182568066927284, 1.2798772354275727, 1.3538666751582975, 1.4426259039919596, 1.5489853358570191, 1.6762658237220625, 1.8283407612492941, 2.0096956085876183, 2.225478927469756 ], "original_max_position_embeddings": 32768, "rope_type": "longrope", "short_factor": [ 0.9977997200264581, 1.014658295992452, 1.0349680404997148, 1.059429246056193, 1.0888815016813513, 1.1243301355211495, 1.166977103606075, 1.2182568066927284, 1.2798772354275727, 1.3538666751582975, 1.4426259039919596, 1.5489853358570191, 1.6762658237220625, 1.8283407612492941, 2.0096956085876183, 2.225478927469756 ] }, "rope_theta": 10000.0, "scale_depth": 1.4, "scale_emb": 12, "sparse_config": null, "torch_dtype": "bfloat16", "transformers_version": "4.51.3", "use_cache": true, "vocab_size": 73448}12345678910111213{ "bos_token_id": 1, "do_sample": true, "eos_token_id": [ 2, 73440 ], "pad_token_id": 2, "temperature": 0.8, "top_p": 0.8, "transformers_version": "4.51.3", "trust_remote_code": true}123version https://git-lfs.github.com/spec/v1oid sha256:146c31f9e7684c662fb314c0132dcb6b71ee3c746aedc864a3739bd99541865bsize 9551568123456789101112131415161718192021222324252627282930313233{ "additional_special_tokens": [ "<|im_end|>", "<|im_start|>", "<|tool_call|>", "<|execute_start|>", "<|execute_end|>", "<|fim_prefix|>", "<|fim_middle|>", "<|fim_suffix|>" ], "bos_token": { "content": "<s>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "eos_token": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "unk_token": { "content": "<unk>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }}123version https://git-lfs.github.com/spec/v1oid sha256:bb74d51116831c3bf65db812c553f94ab0c88dcf97a5bbb37e3504f6d359c530size 1181204123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118{ "add_bos_token": true, "add_eos_token": false, "add_prefix_space": null, "added_tokens_decoder": { "0": { "content": "<unk>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "1": { "content": "<s>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "2": { "content": "</s>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73440": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73441": { "content": "<|im_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73442": { "content": "<|tool_call|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73443": { "content": "<|execute_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73444": { "content": "<|execute_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73445": { "content": "<|fim_prefix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73446": { "content": "<|fim_middle|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "73447": { "content": "<|fim_suffix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "additional_special_tokens": [ "<|im_end|>", "<|im_start|>", "<|tool_call|>", "<|execute_start|>", "<|execute_end|>", "<|fim_prefix|>", "<|fim_middle|>", "<|fim_suffix|>" ], "bos_token": "<s>", "chat_template": "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}", "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "extra_special_tokens": {}, "legacy": true, "model_max_length": 1000000000000000019884624838656, "pad_token": null, "sp_model_kwargs": {}, "spaces_between_special_tokens": false, "tokenizer_class": "LlamaTokenizer", "unk_token": "<unk>", "use_default_system_prompt": false}README.mdAdded+123
added_tokens.jsonAdded+10
config.jsonAdded+81
generation_config.jsonAdded+13
model.safetensorsAdded+3
special_tokens_map.jsonAdded+33
tokenizer.jsonAdded
tokenizer.modelAdded+3
tokenizer_config.jsonAdded+118