Getting Started with Stable Beluga 2

Aug 27, 2023 | Educational

Welcome to this user-friendly guide on how to leverage the capabilities of the latest model from Stability AI: Stable Beluga 2. With its unique features and streamlined format, you’ll be generating text in no time!

What is Stable Beluga 2?

Stable Beluga 2 is an advanced language model fine-tuned on an Orca-style dataset, based on Llama2 70B architecture. This model is engineered for performance with smaller file sizes and enhanced loading efficiency using mechanisms like bfloat16 weight storage and Safetensors.

How to Use Stable Beluga 2

To begin chatting with Stable Beluga 2, simply follow this code snippet:

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

tokenizer = AutoTokenizer.from_pretrained("stabilityai/StableBeluga2", use_fast=False)
model = AutoModelForCausalLM.from_pretrained("stabilityai/StableBeluga2", torch_dtype=torch.float16, low_cpu_mem_usage=True, device_map="auto")

system_prompt = "### System:\nYou are Stable Beluga, an AI that follows instructions extremely well. Help as much as you can. Remember, be safe, and don't do anything illegal.\n\n### User: message"
prompt = f"### User: message\n\n### Assistant:"

inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
output = model.generate(**inputs, do_sample=True, top_p=0.95, top_k=0, max_new_tokens=256)
print(tokenizer.decode(output[0], skip_special_tokens=True))

Understanding the Code

Imagine Stable Beluga 2 as a bakery. You need your ingredients to bake the perfect cake (which in this case is the text output). The ingredients consist of:

  • Importing Libraries: Just as you’d gather your baking tools, you’re importing the necessary libraries to retrieve the model’s functions.
  • Initializing Tokenizer and Model: This is like preparing your oven. You set it to the right temperature (in this case, loading the model in low-memory mode) to ensure your cake turns out perfectly.
  • Writing Prompts: Similar to mixing your ingredients, you compose a prompt that instructs the AI on what to generate.
  • Generating Output: Finally, when the cake is baked, you take it out of the oven—this is the moment when the model produces a text output based on your input.

Troubleshooting Tips

If you encounter any issues while using Stable Beluga 2, consider these troubleshooting steps:

  • Memory Issues: Ensure that your system has enough RAM. If you’re running out of memory, try lowering your batch size or adjusting settings like low_cpu_mem_usage.
  • Model Loading Errors: Check your internet connection if the model fails to load. A stable connection is crucial for retrieving necessary components.
  • Output Errors: If the model’s output seems off, consider revising your system prompt or user input to be clearer or more descriptive.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Key Features of Stable Beluga 2

This model comes with cutting-edge features such as:

  • Lightweight storage with bfloat16 weights for smaller file sizes.
  • Efficient shard storage for optimized data retrieval.
  • Rapid loading times using Safetensors, which reduces RAM usage.

Conclusion

Stable Beluga 2 stands as a testament to innovation in AI language models. Its unique combination of features not only enhances performance but also broadens accessibility for various users.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox