My Journey with MiniCPM3-4B A Personal Exploration of Language Models

Image for the article 'QuantFactory_MiniCPM3-4B-GGUF_output' showing key insights of the topic.

![QuantFactory Banner](https://lh7-rt.googleusercontent.com/doc/s/zAD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)

Discovering MiniCPM3-4B

Hello there! If you’ve been following the whirlwind of advancements in language models, you know it can be both exhilarating and a bit overwhelming. I’ve spent countless hours diving into this fascinating realm, and today, I want to share my personal reflections on MiniCPM3-4B, a model that’s been making waves in the community.

What Makes MiniCPM3-4B Unique?

A Memory That Resonates

One of the standout features of MiniCPM3-4B is its 32k context window. Imagine having a conversation with a friend who recalls every little detail from your past chats. That’s what this model strives for—creating interactions that feel more authentic and connected. Think about how this could change customer service interactions or enhance storytelling, where every subtlety matters. It’s like chatting with someone who truly understands you.

A Meaningful Leap Forward

If you’ve experimented with earlier iterations like MiniCPM1.0 or MiniCPM2.0, you’re in for a pleasant surprise with MiniCPM3-4B. This isn’t merely an upgrade; it feels like entering a new dimension of possibilities. This model doesn’t just spit out text; it can analyze data, assist with coding, and adapt to your unique requirements. I often think of it as a creative Swiss Army knife. I still remember the first time I turned to a language model for coding help—it was as if I had a knowledgeable friend right beside me, guiding me through the process.

Inspiring Real-World Applications

So, what can you actually do with MiniCPM3-4B? The potential is genuinely thrilling! You could create chatbots that mimic human conversation, compose engaging articles, or tackle complex data analyses. Its user-friendly design welcomes anyone curious about AI. Whether you’re a developer, a researcher, or just someone intrigued by technology, this model opens up a treasure trove of opportunities. Personally, I love using AI to brainstorm ideas for my projects, and the collaborative nature of this model is simply fantastic.

Getting Your Hands Dirty with MiniCPM3-4B

Ready to Dive In?

If you’re itching to get started, let’s roll up our sleeves and explore MiniCPM3-4B using the Transformers library. If you enjoy coding, this could turn into an exciting project:

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

path = "openbmb/MiniCPM3-4B"
device = "cuda"  # or "cpu" if you don't have a GPU

tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)

messages = [{"role": "user", "content": "Hello, how can I use MiniCPM3-4B?"}]
model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(device)

model_outputs = model.generate(
    model_inputs,
    max_new_tokens=1024,
    top_p=0.7,
    temperature=0.7
)

output_token_ids = [model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs))]
responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]
print(responses)

Exploring with vLLM

If you’re leaning towards using vLLM, here’s a straightforward setup to help you get started:

from transformers import AutoTokenizer
from vllm import LLM, SamplingParams

model_name = "openbmb/MiniCPM3-4B"
prompt = [{"role": "user", "content": "Tell me about MiniCPM3-4B."}]
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)

input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
llm = LLM(model=model_name, trust_remote_code=True, tensor_parallel_size=1)

sampling_params = SamplingParams(top_p=0.7, temperature=0.7, max_tokens=1024, repetition_penalty=1.02)
outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)

print(outputs[0].outputs[0].text)

How Does MiniCPM3-4B Stack Up?

Let’s take a moment to compare MiniCPM3-4B with its peers. It’s always interesting to see how these models measure up against one another:

| Benchmark | MiniCPM3-4B | Phi-3.5-mini-Instruct | GPT-3.5-Turbo-0125 |

|-----------|-------------|------------------------|---------------------|

| MMLU | 66.3 | 68.4 | 69.2 |

| BBH | 70.2 | 68.6 | 70.3 |

| IFEVAL | 68.4 | 49.4 | 58.8 |

From this comparison, it’s clear that MiniCPM3-4B holds its own, particularly when it comes to understanding and generating responses. Watching the evolution of these models is a captivating journey, and it’s exciting to witness the strides we’ve made in AI.

Reflecting on My Experience

As I look back on my time with MiniCPM3-4B, I can’t help but feel a sense of excitement for what this model brings to the table. Its remarkable features and adaptability make it a valuable tool for anyone eager to delve into the world of AI.

Yet, amidst all this technological wonder, let’s not forget the human touch. As you engage with the content it generates, maintain a critical perspective. No matter how advanced these models become, they can never replace the richness of human experience.

License Information

This repository operates under the [Apache-2.0 License](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE), and the model weights are available for academic research. If you’re considering commercial use, just fill out a [registration questionnaire](https://modelbest.feishu.cn/share/base/forms/hrcnpV5ZT9EJ6xYjh3Kx0J6v8g).

For more details and a deeper dive into the technical aspects, check out the [MiniCPM Repo](https://github.com/OpenBMB/MiniCPM) and the [MiniCPM Paper](https://arxiv.org/abs/2404.06395).

Join the conversation on [Discord](https://discord.gg/3cGQn9b3YM) and connect with a community of enthusiasts eager to share and learn!