|
| 1 | +<!--Copyright 2025 the HuggingFace Team. All rights reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +
|
| 15 | +
|
| 16 | +⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be rendered properly in your Markdown viewer. |
| 17 | +
|
| 18 | +--> |
| 19 | +*This model was released on 2025-09-01 and added to Hugging Face Transformers on 2025-09-15.* |
| 20 | + |
| 21 | + |
| 22 | +# LongCatFlash |
| 23 | + |
| 24 | +## Overview |
| 25 | + |
| 26 | +The LongCatFlash model was proposed in [LongCat-Flash Technical Report](https://huggingface.co/papers/2509.01322) by the Meituan LongCat Team. |
| 27 | +LongCat-Flash is a 560B parameter Mixture-of-Experts (MoE) model that activates 18.6B-31.3B parameters dynamically (average ~27B). The model features a shortcut-connected architecture enabling high inference speed (>100 tokens/second) and advanced reasoning capabilities. |
| 28 | + |
| 29 | +The abstract from the paper is the following: |
| 30 | + |
| 31 | +*We present LongCat-Flash, a 560 billion parameter Mixture-of-Experts (MoE) language model featuring a dynamic computation mechanism that activates 18.6B-31.3B parameters based on context (average ~27B). The model incorporates a shortcut-connected architecture enabling high inference speed (>100 tokens/second) and demonstrates strong performance across multiple benchmarks including 89.71% accuracy on MMLU and exceptional agentic tool use capabilities.* |
| 32 | + |
| 33 | +Tips: |
| 34 | + |
| 35 | +- LongCat-Flash uses a unique shortcut-connected MoE architecture that enables faster inference compared to traditional MoE models |
| 36 | +- The model supports up to 128k context length for long-form tasks |
| 37 | +- Dynamic parameter activation makes it computationally efficient while maintaining high performance |
| 38 | +- Best suited for applications requiring strong reasoning, coding, and tool-calling capabilities |
| 39 | +- The MoE architecture includes zero experts (nn.Identity modules) which act as skip connections, allowing tokens to bypass expert computation when appropriate |
| 40 | + |
| 41 | +This model was contributed by [Molbap](https://huggingface.co/Molbap). |
| 42 | +The original code can be found [here](https://huggingface.co/meituan-longcat/LongCat-Flash-Chat). |
| 43 | + |
| 44 | +## Usage examples |
| 45 | + |
| 46 | +The model is large: you will need 2x8 H100 to run inference. |
| 47 | +```python |
| 48 | +# launch_longcat.py |
| 49 | +from transformers import LongcatFlashForCausalLM, AutoTokenizer |
| 50 | +import torch |
| 51 | + |
| 52 | +model_id = "meituan-longcat/LongCat-Flash-Chat" |
| 53 | + |
| 54 | +tokenizer = AutoTokenizer.from_pretrained(model_id) |
| 55 | + |
| 56 | +chat = [ |
| 57 | + {"role": "user", "content": "Hello! What is the capital of France? What can you tell me about it?"}, |
| 58 | +] |
| 59 | + |
| 60 | +model = LongcatFlashForCausalLM.from_pretrained( |
| 61 | + model_id, |
| 62 | + tp_plan="auto", |
| 63 | + dtype=torch.bfloat16, |
| 64 | + ) |
| 65 | + |
| 66 | +inputs = tokenizer.apply_chat_template( |
| 67 | + chat, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device) |
| 68 | + |
| 69 | +outputs = model.generate(inputs, max_new_tokens=30) |
| 70 | +print(tokenizer.batch_decode(outputs)) |
| 71 | +``` |
| 72 | + |
| 73 | +To run with TP, you will need torchrun: |
| 74 | + |
| 75 | +```bash |
| 76 | +torchrun --nproc_per_node=8 --nnodes=2 --node_rank=0 | 1 --rdzv-id <an_id> --rdzv-backend c10d --rdzv-endpoint $NODE_ID:$NODE_PORT --log-dir ./logs_longcat launch_longcat.py |
| 77 | +``` |
| 78 | + |
| 79 | +And you'll get a nice generation: |
| 80 | +```json |
| 81 | +[Round 0] USER:Hello! What is the capital of France? What can you tell me about it? ASSISTANT:Hello! 😊 The capital of France is Paris, one of the most famous and beloved cities in the world. Here’s a quick overview of what makes Paris special: |
| 82 | +1. Iconic Landmarks |
| 83 | + |
| 84 | + Eiffel Tower – The global symbol of France, built in 1889 for the World's Fair. |
| 85 | + Notre-Dame Cathedral – A masterpiece of Gothic architecture (currently under restoration after the 2019 fire). |
| 86 | + Louvre Museum – The world’s largest art museum, home to the Mona Lisa and Venus de Milo. |
| 87 | + Sacré-Cœur Basilica – A stunning white church atop Montmartre with panoramic views. |
| 88 | + Arc de Triomphe – Honors French military victories, with the Tomb of the Unknown Soldier beneath it. |
| 89 | + Champs-Élysées – A glamorous avenue leading to the Arc de Triomphe, lined with shops and cafés. |
| 90 | + |
| 91 | +2. Culture & Arts |
| 92 | + |
| 93 | + Paris is the "City of Light" (La Ville Lumière), a nickname from its early adoption of street lighting and its role as a center of enlightenment. |
| 94 | + It’s a global hub for fashion (haute couture, Paris Fashion Week) and art (Impressionism, Picasso, Dali). |
| 95 | + Famous literary figures like Hemingway, Fitzgerald, and Sartre lived and wrote here. |
| 96 | + |
| 97 | +3. Food & Cuisine |
| 98 | + |
| 99 | + Croissants, baguettes, macarons, and crème brûlée are just a few of its culinary delights. |
| 100 | + Paris has over 100 Michelin-starred restaurants and countless cozy bistros. |
| 101 | + The Marché d’Aligre and Rue Mouffetard are great for fresh produce and local flavors. |
| 102 | + |
| 103 | +4. History & Politics |
| 104 | + |
| 105 | + Founded in the 3rd century BC by the Parisii tribe, it became a major European city under the Romans. |
| 106 | + The French Revolution (1789–1799) began here, leading to the fall of the monarchy. |
| 107 | + Today, it’s the political and economic heart of France, housing the French President’s residence (Élysée Palace) and the National Assembly. |
| 108 | + |
| 109 | +** |
| 110 | +``` |
| 111 | + |
| 112 | +## LongcatFlashConfig |
| 113 | + |
| 114 | +[[autodoc]] LongcatFlashConfig |
| 115 | + |
| 116 | +## LongcatFlashPreTrainedModel |
| 117 | + |
| 118 | +[[autodoc]] LongcatFlashPreTrainedModel |
| 119 | + - forward |
| 120 | + |
| 121 | +## LongcatFlashModel |
| 122 | + |
| 123 | +[[autodoc]] LongcatFlashModel |
| 124 | + - forward |
| 125 | + |
| 126 | +## LongcatFlashForCausalLM |
| 127 | + |
| 128 | +[[autodoc]] LongcatFlashForCausalLM |
0 commit comments