🐨

Microsoftから「UserLM-8b」という面白いモデルが登場!

に公開

UserLM-8b

このモデルはズバリ、従来の生成AIモデルのような「Assistant」側の生成をするのではなくて、「User」側の生成をおこなうモデルです。

つまり、普段作っているAIエージェントとの会話シミュレーションを行うことに特化したモデルです。
ユーザー向けのモデルではなくて、開発テスト用のエンジニア向けモデルという感じですね。

以下は論文から抜粋ですが、
今までは従来の生成AIモデルにユーザー役をさせていましたが、アシスタントに特化しているのでユーザーの曖昧さや不完全さ、イレギュラーさという観点で精度としては不十分だということがわかったそうです。
ベースモデルはLlama3-8b-Baseとのこと。

イメージ

世の中の生成AIモデル

開発テストの効率化のためユーザー側の質問もAIで自動化

しかし、ユーザー役を任せても本来のユーザーの文章とは自然さが乖離することが判明

開発テスト時のユーザー役に特化したモデル爆誕!

よりユーザーっぽいテキスト生成を可能としていて、その結果AIエージェントの自動シミュレーション時のテストの品質の向上が狙える!

動かしてみる

さあ動かそうと思ったものの、モデルサイズが33GiBとゲーミングPCでも全然厳しいので4bitに量子化を行います。

コードはこちら

main.py
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch
 
def main():
    # Load the model and tokenizer
    model_path = "microsoft/UserLM-8b"  
    tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
    
    # Configure 4-bit quantization
    quantization_config = BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_compute_dtype=torch.bfloat16,
        bnb_4bit_quant_type="nf4",
        bnb_4bit_use_double_quant=True,
    )
    
    model = AutoModelForCausalLM.from_pretrained(
        model_path,
        quantization_config=quantization_config,
        device_map="cuda",
        trust_remote_code=True
    )

    system_prompt = """
    You are an engineer struggling with a TypeScript type error.
    """
 
    # Create a conversation
    messages = [
        {
            "role": "system", 
            "content": system_prompt
        }
    ]
    inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
 
    end_token = "<|eot_id|>"
    end_token_id = tokenizer.encode(end_token, add_special_tokens=False)
 
    end_conv_token = "<|endconversation|>"
    end_conv_token_id = tokenizer.encode(end_conv_token, add_special_tokens=False)
 
    outputs = model.generate(
        input_ids=inputs,
        do_sample=True,
        top_p=0.8,
        temperature=1,
        max_new_tokens=1000,
        eos_token_id=end_token_id,
        pad_token_id=tokenizer.eos_token_id,
        bad_words_ids=[[token_id] for token_id in end_conv_token_id]
    )
    response = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
    print(response)
 
 
if __name__ == "__main__":
    main()


システムプロンプトはTypeScriptの型エラーに苦戦しているエンジニアにします。(日本語対応してないので英語です)

You are an engineer struggling with a TypeScript type error.


実行結果

 You are an engineer struggling with a TypeScript type error.
    Your app requires a user to be logged in to view their profile,
    but you're getting an error because the user object is possibly 'undefined'.

    Can you please make the user object required?
    You can only use exact matches and wildcards, no regex or else.
    I can't use any regex or else, only exact matches, and wildcards.
    Make the changes to this line only please: const user = await strapi.query('plugin::users-permissions', 'api::users-permissions.user').findOne({
                fields: ['-password', '-salt', '-hash', '-email', '-mobile_phone', '-mobile_country', '-mobile_network', '-birth_date', '-deleted_at', '-first_name', '-last_name', '-middle_name', '-last_name_patronymic', '-last_name_matronymic', '-name', '-job_title', '-description', '-company_name', '-company_phone', '-company_address', '-address', '-city', '-country', '-timezone', '-locale', '-verified', '-custom', '-avatar', '-avatar_medium', '-avatar_large', '-avatar_hd', '-public_messages', '-public_messages_limit', '-private_messages', '-private_messages_limit', '-private_messages_unread', '-last_login', '-last_ip', '-failed_login_count', '-is_super_admin', '-is_staff', '-is_admin', '-created_at', '-created_by', '-updated_at', '-updated_by'],
                where: {
                   ...filter,
                    'id': user_id,
                },
                populate: ['avatar', 'avatar_medium', 'avatar_large', 'avatar_hd'],
                select: ['-password', '-salt', '-hash', '-email', '-mobile_phone', '-mobile_country', '-mobile_network', '-birth_date', '-deleted_at', '-first_name', '-last_name', '-middle_name', '-last_name_patronymic', '-last_name_matronymic', '-name', '-job_title', '-description', '-company_name', '-company_phone', '-company_address', '-address', '-city', '-country', '-timezone', '-locale', '-verified', '-custom', '-public_messages', '-public_messages_limit', '-private_messages', '-private_messages_limit', '-private_messages_unread', '-last_login', '-last_ip', '-failed_login_count', '-is_super_admin', '-is_staff', '-is_admin', '-created_at', '-created_by', '-updated_at', '-updated_by', 'avatar', 'avatar_medium', 'avatar_large', 'avatar_hd'],
            });

...おや??

おそらく、期待する出力は以下のような感じです。

I’m getting a TypeScript error saying the user object might be undefined.
Should I use a non-null assertion or change the type definition?

この後も何回かsystem_promptを変えてみたのですが、本来期待するような出力はできませんでした...
おそらく4bitに量子化していることが原因っぽいので、オリジナルサイズか8bit量子化モデルで動かしたらどうなるか見てみたいですね。(誰か高スペックなPCを持ってる人がやってくれると信じて.)

ヘッドウォータース

Discussion