Alibaba's Qwen team releases Qwen 3.8 models with open weights under the Apache 2.0 license
Back to Tutorials
aiTutorialbeginner

Alibaba's Qwen team releases Qwen 3.8 models with open weights under the Apache 2.0 license

August 14, 202661 views5 min read

Learn how to download and use Alibaba's Qwen 3.8 open-source language model for text generation and coding tasks in a beginner-friendly tutorial.

Introduction

In this tutorial, you'll learn how to use Alibaba's Qwen 3.8 open-source language model to build a simple text processing application. This model, released under the Apache 2.0 license, offers powerful capabilities for coding tasks and document processing. We'll walk through downloading the model, setting up your environment, and running basic text generation tasks.

Prerequisites

Before starting this tutorial, you'll need:

  • A computer with internet access
  • Python 3.8 or higher installed
  • Basic understanding of command-line interfaces
  • Approximately 2-3 GB of free disk space for model files

Step-by-step Instructions

1. Setting Up Your Python Environment

First, we need to create a dedicated Python environment to avoid conflicts with other projects. This ensures that all the required packages are properly installed without interfering with your system's Python setup.

1.1 Create a Virtual Environment

python -m venv qwen_env

This command creates a new virtual environment named 'qwen_env' in your current directory.

1.2 Activate the Virtual Environment

On Windows:

qwen_env\Scripts\activate

On macOS and Linux:

source qwen_env/bin/activate

Once activated, you'll see '(qwen_env)' at the beginning of your command prompt, indicating that you're working in the isolated environment.

2. Installing Required Packages

Next, we'll install the necessary libraries to work with the Qwen model. The Hugging Face Transformers library is the most popular tool for working with open-source language models.

2.1 Install Transformers Library

pip install transformers torch

This installs the Transformers library (which provides easy access to many pre-trained models) and PyTorch (the deep learning framework that powers most modern AI models).

3. Downloading the Qwen 3.8 Model

Alibaba's Qwen 3.8 models are hosted on Hugging Face, which provides a convenient way to access open-source AI models. We'll download the model using the Transformers library.

3.1 Download the Model

First, you'll need to identify the correct model identifier. For this tutorial, we'll use the Qwen 3.8 model variant:

from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "Qwen/Qwen-3.8"

# Download tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

This code downloads the tokenizer and model files from Hugging Face. The tokenizer converts text into numerical tokens that the model can process, while the model itself performs the actual text generation.

4. Testing the Model

Now that we've downloaded the model, let's test it with a simple prompt to see how it works.

4.1 Create a Test Script

Create a new file called test_qwen.py and add the following code:

from transformers import AutoTokenizer, AutoModelForCausalLM

# Load model and tokenizer
model_name = "Qwen/Qwen-3.8"

print("Loading tokenizer...")
tokenizer = AutoTokenizer.from_pretrained(model_name)

print("Loading model...")
model = AutoModelForCausalLM.from_pretrained(model_name)

# Test prompt
prompt = "Write a short introduction about artificial intelligence."

# Tokenize the input
inputs = tokenizer(prompt, return_tensors="pt")

# Generate text
outputs = model.generate(**inputs, max_new_tokens=100)

# Decode the output
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)

print("Input prompt:", prompt)
print("Generated text:", generated_text)

4.2 Run the Test Script

python test_qwen.py

This script will load the Qwen 3.8 model and generate a response to your prompt. You should see output similar to:

Input prompt: Write a short introduction about artificial intelligence.
Generated text: Artificial intelligence (AI) is a branch of computer science that aims to create software or machines that exhibit human-like intelligence. This can include learning from experience, understanding natural language, solving problems, and recognizing patterns.

5. Exploring Model Capabilities

Qwen 3.8 is designed to excel in coding tasks and office applications. Let's try a coding example to see how it performs:

5.1 Create a Coding Example Script

from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "Qwen/Qwen-3.8"

# Load model and tokenizer
print("Loading model...")
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Coding prompt
prompt = "Write a Python function that calculates the factorial of a number."

# Tokenize and generate
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=200)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)

print("Prompt:", prompt)
print("Generated code:", generated_text)

5.2 Run the Coding Example

python coding_example.py

This will generate a Python function that calculates factorials, demonstrating the model's coding capabilities.

6. Customizing Generation Parameters

The model's output can be customized using various parameters to control the creativity and focus of the generated text.

6.1 Modify Generation Parameters

from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "Qwen/Qwen-3.8"

# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Prompt
prompt = "Explain quantum computing in simple terms."
inputs = tokenizer(prompt, return_tensors="pt")

# Generate with custom parameters
outputs = model.generate(
    **inputs,
    max_new_tokens=150,
    temperature=0.7,
    top_p=0.9,
    do_sample=True
)

generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print("Generated text:", generated_text)

The parameters we're using:

  • max_new_tokens: Controls how many new tokens the model generates
  • temperature: Higher values (0.7) make output more random; lower values (0.3) make it more focused
  • top_p: Controls the nucleus sampling for more coherent text
  • do_sample: Enables sampling for more creative outputs

Summary

In this tutorial, you've learned how to set up and use Alibaba's Qwen 3.8 open-source model. You've created a Python environment, downloaded the model, and generated text using different prompts. You've also explored how to customize generation parameters to get different types of responses. This foundational knowledge allows you to build more complex applications using the Qwen 3.8 model for tasks like code generation, document summarization, and more. The Apache 2.0 license means you can use this model freely in both personal and commercial projects.

Source: The Decoder

Related Articles