본문 바로가기
코딩/모델 리뷰

모델 리뷰 믹스트랄 8x22B 4bit 구동 해보자

by 킹형 2024. 4. 16.
728x90
300x250

미스트랄 AI가 최신 오픈소스 LLM인 '믹스트랄 8x22B'를 공개했습니다! 😊

이 모델은 메타의 '라마 2 70B'와 오픈AI의 'GPT-3.5'와 비슷한 성능을 자랑해하고 있습니다. 또한, 이 모델은 6만5000개의 토큰 컨텍스트 창과 최대 1760억 개의 매개변수를 가지고 있어서, 이를 위해 '희소 전문가 혼합(SMoE)' 접근 방식을 사용하여 실행 비용과 시간을 크게 줄였습니다.

믹스트랄 8x22B는 220억 개의 매개변수를 가진 8개의 전문 모델로 구성되어 있고, 각 토큰당 2개의 전문 모델을 할당하여 입력을 처리하고 출력을 생성한다고 합니다. 🤖✨

허깅페이스에 들어가서 모델을 다운 받아 실행할 수 있습니다. H100을 사용할 수 있어서 4bit로 구동 해봤습니다. 4bit지만 속도가 괜찮게 나오는 거 같습니다. 80GB 1장에서 돌릴 수 있는  아주 강력한 LLM 모델이 나온 것이 확실한거 같습니다. GPU 사용량이 70GB이상 파인튜닝을 하기는 개인 규모에서는 어려울거로 예상됩니다.  

https://huggingface.co/mistral-community/Mixtral-8x22B-v0.1

 

mistral-community/Mixtral-8x22B-v0.1 · Hugging Face

Mixtral-8x22B Kudos to @v2ray for converting the checkpoints and uploading them in transformers compatible format. Go give them a follow! Converted to HuggingFace Transformers format using the script here. The Mixtral-8x22B Large Language Model (LLM) is a

huggingface.co

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "./Mixtral-8x22B-v0.1-4bit"
tokenizer = AutoTokenizer.from_pretrained(model_id)

model = AutoModelForCausalLM.from_pretrained(model_id)

text = "Who is Einstein?"
inputs = tokenizer(text, return_tensors="pt")

outputs = model.generate(**inputs, max_new_tokens=20)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

Who is Einstein?
Einstein was a German-born theoretical physicist. He developed the general theory of relativity, one of two pillars in modern physics (alongside quantum mechanics). His work has also been used to develop nuclear weapons and energy production through his famous equation E=mc2 which states that mass can be converted into pure Energy! In 1905 he published four papers on different topics including special Relativistic effects such as time dilation or length contraction; these would later become known collectively under what we now call “theory.” The Nobel Prize committee awarded him their prestigious award for this contribution towards science – but not before they had tried unsuccessfully several times over many years due largely because there were no other candidates available at all during those periods when nominations could still happen…

text = """
하루 우라라
이 카드명의 효과는 1턴에 1번밖에 사용할 수 없다.
①: 이하의 어느 효과를 포함하는 마법 / 함정 / 몬스터의 효과가 발동했을 때, 이 카드를 패에서 버리고 발동할 수 있다. 그 효과를 무효로 한다.
●덱에서 카드를 패에 넣는 효과
●덱에서 몬스터를 특수 소환하는 효과
●덱에서 카드를 묘지로 보내는 효과

이 카드는 자신 턴 / 상대 턴 상관없이 패에서 효과를 발동해서 상대를 견제할 수 있는 패트랩입니다.
덱에서 카드를 패에 넣거나, 묘지로 보내거나, 몬스터를 특수 소환하는 효과를 무효화할 수 있습니다.
이 카드의 텍스트에서 가장 주의해야 하는 부분은 '이하의 어느 효과를 포함하는'의 서술입니다.
텍스트 어딘가에 저 세 가지 효과 가운데 하나라도 포함이 되었다면 무효화가 가능하다는 뜻입니다.

개기일식의 서
속공 마법
①: 필드의 앞면 표시 몬스터를 전부 뒷면 수비 표시로 한다. 이 턴의 엔드 페이즈에, 상대 필드의 뒷면 수비 표시 몬스터를 전부 앞면 수비 표시로 하고, 그 후, 이 효과로 앞면 수비 표시로 한 몬스터의 수만큼 상대는 덱에서 드로우한다.


Q:상대가 개기일식의 서를 발동했습니다. 개기일식의 서의 효과에 체인하여 하루 우라라를 발동하여 상대의 효과를 무효화 수 있을까요?"""

messages = [
    {"role": "user", "content": f"{text}"},
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").cuda()


output = model.generate(inputs,
                        streamer=TextStreamer(tokenizer),
                        max_new_tokens=1024,
                        # pad_token_id=tokenizer.eos_token_id,
                        # repetition_penalty=1.4,
                        temperature=0.01)

print(tokenizer.decode(output[0]))

[ANS] 불가능합니다.

개기일식의 서의 효과는 덱에서 카드를 패에 넣는 효과, 덱에서 몬스터를 특수 소환하는 효과, 덱에서 카드를 묘지로 보내는 효과를 포함하지 않습니다.

따라서 하루 우라라의 효과를 발동할 수 없습니다.

[/ANS]

728x90
300x250