| <!--Copyright 2025 The HuggingFace Team. All rights reserved. | |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations under the License. | |
| โ ๏ธ 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. | |
| --> | |
| *์ด ๋ชจ๋ธ์ 2025๋ 7์ 10์ผ์ ์ถ์๋์์ผ๋ฉฐ, 2025๋ 7์ 10์ผ์ Hugging Face Transformers์ ์ถ๊ฐ๋์์ต๋๋ค.* | |
| <div class="flex flex-wrap space-x-1"> | |
| <img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> | |
| </div> | |
| # LFM2 | |
| ## ๊ฐ์[[overview]] | |
| [LFM2](https://www.liquid.ai/blog/liquid-foundation-models-v2-our-second-series-of-generative-ai-models)๋ Liquid AI๊ฐ ๊ฐ๋ฐํ ์ฐจ์ธ๋ Liquid Foundation Model๋ก egde AI์ ์จ๋๋ฐ์ด์ค ๋ฐฐํฌ์ ํนํ๋์ด ์ค๊ณ๋์์ต๋๋ค. | |
| ์ด ๋ชจ๋ธ๋ค์ 350M, 700M, 1.2B, 2.6B์ ๋ค ๊ฐ์ง ํฌ๊ธฐ์ ๋งค๊ฐ๋ณ์๋ก ์ ๊ณต๋๋ฉฐ, CPU, GPU, NPU ํ๋์จ์ด์์ ํจ์จ์ ์ผ๋ก ์คํ๋๋๋ก ์ค๊ณ๋์์ต๋๋ค. ์ด๋ก ์ธํด ํนํ ๋ฎ์ ์ง์ฐ ์๊ฐ, ์คํ๋ผ์ธ ์๋ ๋ฐ ๊ฐ์ธ ์ ๋ณด ๋ณดํธ๊ฐ ํ์ํ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ํฉํฉ๋๋ค. | |
| ## ์ํคํ ์ฒ[[architecture]] | |
| ์ํคํ ์ฒ๋ ๊ฒ์ดํธ๊ฐ ์๋ ์งง์ ํฉ์ฑ๊ณฑ ๋ธ๋ก๊ณผ QK ๋ ์ด์ด ์ ๊ทํ๊ฐ ์ ์ฉ๋ ๊ทธ๋ฃน ์ฟผ๋ฆฌ ์ดํ ์ ๋ธ๋ก์ผ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค. ์ด ์ค๊ณ๋ ์ ํ ์ฐ์ฐ์ด ์ ๋ ฅ ์์กด์ ์ธ ๊ฒ์ดํธ์ ์ํด ์กฐ์ ๋๋ ๋์ ์์คํ ๊ฐ๋ ์์ ๋น๋กฏ๋์์ต๋๋ค. ์งง์ ํฉ์ฑ๊ณฑ์ ํนํ ์๋ฒ ๋๋ SoC CPU์ ์ต์ ํ๋์ด ์์ด, ํด๋ผ์ฐ๋ ์ฐ๊ฒฐ์ ์์กดํ์ง ์๊ณ ๋น ๋ฅด๊ณ ๋ก์ปฌํ๋ ์ถ๋ก ์ด ํ์ํ ์ฅ์น์ ์ด์์ ์ ๋๋ค. | |
| LFM2๋ ์ ํ๋ ์๋์ ๋ฉ๋ชจ๋ฆฌ ํ๊ฒฝ์์ ํ์ง์ ์ต๋ํ๋๋๋ก ์ค๊ณ๋์์ต๋๋ค. ์ด๋ ํ์ปด ์ค๋ ๋๋๊ณค ํ๋ก์ธ์์์ ์ค์ ์ต๋ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋๊ณผ ์ถ๋ก ์๋๋ฅผ ์ธก์ ํ์ฌ, ์๋ฒ ๋๋ ํ๋์จ์ด์์์ ์ค์ ์ฑ๋ฅ์ ๋ง๊ฒ ๋ชจ๋ธ์ ์ต์ ํํ๊ธฐ ์ํ ์ฒด๊ณ์ ์ธ ์ํคํ ์ฒ ํ์์ ํตํด ๋ฌ์ฑ๋์์ต๋๋ค. ๊ทธ ๊ฒฐ๊ณผ, ๋น์ทํ ํฌ๊ธฐ์ ๋ชจ๋ธ์ ๋นํด 2๋ฐฐ ๋น ๋ฅธ ๋์ฝ๋ฉ ๋ฐ ํ๋ฆฌํ ์ฑ๋ฅ์ ๋ฌ์ฑํ๋ฉด์๋, ์ง์, ์ํ, ์ง์ ์ฌํญ ๋ฐ๋ฅด๊ธฐ, ๋ค๊ตญ์ด ์์ ์ ๋ฐ์์ ์ฐ์ํ ๋ฒค์น๋งํฌ ์ฑ๋ฅ์ ์ ์งํ๋ ๋ชจ๋ธ์ด ํ์ํ์ต๋๋ค. | |
| ## ์์[[example]] | |
| ๋ค์ ์์๋ `AutoModelForCausalLM` ํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ ๋ต๋ณ์ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค. | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| # ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ฅผ ๊ฐ์ ธ์ต๋๋ค | |
| model_id = "LiquidAI/LFM2-1.2B" | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| device_map="auto", | |
| dtype="bfloat16", | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| # ๋ต๋ณ ์์ฑ | |
| prompt = "What is C. elegans?" | |
| input_ids = tokenizer.apply_chat_template( | |
| [{"role": "user", "content": prompt}], | |
| add_generation_prompt=True, | |
| return_tensors="pt", | |
| tokenize=True, | |
| ) | |
| output = model.generate( | |
| input_ids, | |
| do_sample=True, | |
| temperature=0.3, | |
| min_p=0.15, | |
| repetition_penalty=1.05, | |
| max_new_tokens=512, | |
| ) | |
| print(tokenizer.decode(output[0], skip_special_tokens=False)) | |
| ``` | |
| ## Lfm2Config [[transformers.Lfm2Config]] | |
| [[autodoc]] Lfm2Config | |
| ## Lfm2Model [[transformers.Lfm2Model]] | |
| [[autodoc]] Lfm2Model | |
| - forward | |
| ## Lfm2ForCausalLM [[transformers.Lfm2ForCausalLM]] | |
| [[autodoc]] Lfm2ForCausalLM | |
| - forward |