SSブログ

やっと涼しくなりました。 [相鉄沿線]

やっと涼しくなってきました。







風の流れも変わって、桜山から富士山が見えました。




今週のチョットGPT
先週、GPT-4の性能を上回るらしいXwin-LMというモデルが公開されました。https://huggingface.co/Xwin-LM
Hugging Faceのサイトを見ると、開発したのは、マイクロソフト・リサーチ・アジア(中国)や清華大学の4名の方らしいです。
パラメータ数が、70億(7B)、130億(13B)、700億(70B)の3種類のモデルが公開されていたので、130億のXwin-LM-13B-V0.1 を、BitsAndBytes (https://github.com/TimDettmers/bitsandbytes )を使って4ビットに量子化して動かしてみました。
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch

model_id = "Xwin-LM/Xwin-LM-13B-V0.1"
quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.float32,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
)

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=quantization_config,
    device_map="auto",
)


元のモデルのデータ型は、torch.float32で、ファイルサイズは49GBぐらいありますが、4ビット量子化すると9GB程度のGPUメモリで動かすことができます。

「なぜ多くの日本人は。桜が好きなのですか ?」
 という日本語の問いに対して、
「日本の桜の季節は、毎年春にある。この季節には、桜の花が美しく咲き、日本中が満開になる。日本人は、この桜の季節に、家族や友人と共に桜を見て楽しみ、桜の花を見ることを楽しんでいます。 桜は、日本の国花であり、日本人にとって、桜は国を代表する花であり、日本の美しさを象徴しています。また、桜は春の季節の象徴でもあり、春の来ることを告げる役割も果たしています。」
と、日本語で答えてくれました。
すごい。

AIの言語処理能力のテストで良く使われるBoolQの問題から、
「アテナイ市民は、一生の間五百人評議員を務めることができましたか?」
という問いに対して、
「アテナイの市民は、一生の間に五百人評議員を務めることができました。これは、アテナイの政治制度が非常に幅広い社会参加を促進していたことを示しています。五百人評議員は、市民の代表として政治的な決定を行う機関であり、アテナイの政治的な生活の中心であったため、市民がその中で積極的に働くことが期待されていました。 このような制度は、市民が政治に関与し、社会に貢献できる機会を提供し、アテナイの民主主義的な価値観を強化しました。」
と、それらしい回答をしてくれます。
BoolQでは答えは、true,務めることができた。( https://huggingface.co/datasets/boolq )ということになっていますが、これはテストデータが間違っていて、実際は任期が1年で、生涯で2回までしか務められないので、間違った答えです。

五百人評議会は、中国語では、五百人会議というらしいので、
「アテナイ市民は、一生の間五百人会議の議員を務めることができましたか?」
って、聞いてみたら、

「この問題は、確率と統計学の概念を理解するための基本的な問題です。 解答は、アテナイ市民が一生の間五百人会議の議員を務めることができる確率は、0.5%程度です。 具体的には、以下のような計算で解答を得ます。 1. アテナイ市民の総人口:10,000人 2. 五百人会議の議員数:500人 3. 選抜される確率:1/20(各年の新年祭で選抜される確率)」

って、答えてくれました。賢いのか???

ときどき間違えることは、あるようですがLLMとしては、すごくよくできてると思います。
LLMの分野でも中国の技術進んでますね。
これは、日本ピンチかも...

nice!(14)  コメント(0) 

ヒガンバナ [相鉄沿線]

まだまだ暑い日が続いていますが、もう9月も中旬なんですね。
今年は(も)忙しくて、まだ夏休みをとれていません....




コスモスも咲き始めていました。






ひさしぶりに、チョットGPT
6月に「Microsoftがたった13億のパラメーターでGPT-3.5超えのHumanEval50.6%をたたき出す「phi-1」を発表」https://gigazine.net/news/20230622-phi-1-large-language-model-microsoft/
という記事が出ていましたが、先週Hugging faceに microsoft/phi-1_5 が公開されていました。
https://huggingface.co/microsoft/phi-1_5
モデルのファイルサイズが3GBしかないので、10万円以下のゲーミングノートパソコンでも動かせるサイズですね。

Hugging faceのサンプルをちょっと変えて、Pythonで、曜日を取得する方法を聞いてみました。
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

torch.set_default_device('cuda')
model = AutoModelForCausalLM.from_pretrained(
    "microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(
    "microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto")


inputs = tokenizer(
    'def get_day_of_the_week(d: datetime) -> str:\n    """ ',
     return_tensors="pt", return_attention_mask=False)

outputs = model.generate(**inputs, max_length=200)
text = tokenizer.batch_decode(outputs)[0]
print(text)


def get_day_of_the_week(d: datetime) -> str:
    """ 
    Given a datetime object, returns the day of the week as a string.
    """
    days_of_week = ["Monday", "Tuesday", "Wednesday", 
        "Thursday", "Friday", "Saturday", "Sunday"]
    return days_of_week[d.weekday()]

<|endoftext|>


ちゃんとできてますね。

これはどうかな?
'Why Do Japanese People Love Sakura so Much ?'

Sakura is a type of flower that blooms in the spring and summer, and is often associated with Japan and its culture. It is a symbol of beauty, grace, and renewal, and is often used in traditional Japanese art and literature. But why do Japanese people love Sakura so much? One reason is that Sakura is a reminder of the beauty and fragility of life. In Japan, life is often seen as a precious gift, and people are encouraged to appreciate the simple things in life. Sakura is a symbol of this appreciation, and is often given as a gift to show love and gratitude. Another reason is that Sakura is a symbol of the changing seasons. In Japan, the seasons are divided into four: spring, summer, autumn, and winter. Each season has its own unique beauty, and Sakura is a symbol of the beauty of spring and summer. It is a reminder that even in the midst of the cold and dark winter months, there is still beauty and hope. But Sakura is not just a symbol of beauty and hope. It is also a symbol of resilience and strength. In Japan, there are many examples of people who have overcome great adversity and hardship. Sakura is a symbol of this resilience, and is often used in traditional Japanese art and literature to represent the strength of the human spirit.

すごい。驚きました。

LLMは、大きなモデルほど性能が良くなると考えられていて、1千億パラメータを超えるモデルもいくつも出てきて、高価なGPUを沢山使って動かすものが増えてきていますが、Microsoft phi-1 は、モデルを大きくするのではなく、AIに学習させるデータの質を良くして、性能を上げているそうです。
学習は、量より質ということなのかな?




nice!(18)  コメント(0) 

雨上がり [相鉄沿線]

ちゃんと雨宿りできていたかな






ヤマボウシには、ロリーポップみたいな実が沢山なっていました。

nice!(15)  コメント(0) 

9月になりました [相鉄沿線]

谷戸に吹く風が、すこしだけ涼しく感じるようになりました。(暑さに慣れただけかな?)


もう栗の実が落ちてた。







nice!(15)  コメント(0)