メインコンテンツへスキップ
見出し画像

Google Colab で FreeWilly2-GPTQ を試す

    「Google Colab」で「FreeWilly2-GPTQ」を試したのでまとめました。

    【注意】Google Colab Pro/Pro+ の A100で動作確認しています。

    前回

    1. AutoGPTQ

    「AutoGPTQ」を使って「FreeWilly2」の「Google Colab」での実行に挑戦してみます。

    2. Colabでの学習

    Google Colabでの学習手順は、次のとおりです。

    (1) メニュー「編集→ノートブックの設定」で、「ハードウェアアクセラレータ」で「GPU」の「A100」を選択。

    (2) パッケージのインストール。

    # パッケージのインストール
    %cd /content
    !git clone https://github.com/PanQiWei/AutoGPTQ
    %cd AutoGPTQ
    !pip install . 
    !pip install git+https://github.com/huggingface/transformers

    (2) トークナイザーとモデルの準備。

    from transformers import AutoTokenizer, pipeline, logging
    from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
    
    # トークナイザーとモデルの準備
    model_name_or_path = "TheBloke/FreeWilly2-GPTQ"
    model_basename = "gptq_model-4bit--1g"
    tokenizer = AutoTokenizer.from_pretrained(
        model_name_or_path,
        use_fast=True
    )
    model = AutoGPTQForCausalLM.from_quantized(
        model_name_or_path,
        model_basename=model_basename,
        inject_fused_attention=False, # 現時点では70Bに必要
        use_safetensors=True,
        trust_remote_code=True,
        device="cuda:0",
        use_triton=False,
        quantize_config=None
    )

    (3) 推論の実行。

    # プロンプトの準備
    prompt='''### System:
    This is a system prompt, please behave and help the user.
    
    ### User:
    What is Bocchi-chan's personality from BOCCHI THE ROCK?
    
    ### Assistant:
    '''
    
    # 推論の実行
    input_ids = tokenizer(prompt, return_tensors='pt').input_ids.cuda()
    output = model.generate(inputs=input_ids, temperature=0.7, max_new_tokens=512)
    print(tokenizer.decode(output[0]))
    <s> ### System:
    This is a system prompt, please behave and help the user.
    
    ### User:
    What is Bocchi-chan's personality from BOCCHI THE ROCK?
    
    ### Assistant:
    Bocchi-chan, also known as Hitori Gotou, is the main character in the manga and anime series "Bocchi The Rock." She is a shy, introverted girl who struggles with social anxiety and has difficulty communicating with others. Despite her challenges, she is passionate about playing the guitar and joins a band, where she learns to overcome her fears and develop friendships. Her personality is relatable to many people who experience social anxiety and shyness, making her a beloved character in the series.</s>

    <s> ### System:
    これはシステムプロンプトです。適切な行動をとり、ユーザーを助けてください。

    ### User:
    ぼっち・ざ・ろっくのぼっちちゃんの性格は?

    ### アシスタント:
    ぼっちちゃん(別名後藤ひとり)は、漫画およびアニメシリーズ「ぼっち・ざ・ろっく!」の主人公です。 彼女は内気で内向的な女の子で、社交不安に苦しみ、他人とのコミュニケーションが苦手です。 困難にもかかわらず、彼女はギターを弾くことに情熱を持っており、バンドに参加し、そこで恐怖を克服し、友情を育むことを学びます。 彼女の性格は、社交不安や内気を経験する多くの人々に共感を与え、シリーズの中で愛されるキャラクターとなっています。</s>



     
     

    npaka

     
     
    プログラマー。iPhone / Android / Unity / ROS / AI / AR / VR / RasPi / ロボット / ガジェット。年2冊ペースで技術書を執筆。アニソン / カラオケ / ギター / 猫 twitter : @npaka123

    あなたへのおすすめ