https://github.com/karpathy/llama2.c


TinyStory 모델 학습 결과 글을 보고 생각 났습니다.


저도 예전에 모델을 학습 하였습니다. 


2023.10.26 학습 시도한 거라 자세하게 기억나진 않습니다.


많은 시행착오 끝에 만들었던 걸로 기억합니다.


그 결과를 공개합니다.


4090 24GB + 3090 24GB = 48GB 훈련 진행했습니다.


지금 train.py 확인 해보니 아래와 같이 설정 되어 있습니다.


(15M Model)

batch_size = 128

max_seq_len = 2048

dim = 288

n_layers = 6

n_heads = 6

n_kv_heads = 6

multiple_of = 32

dropout = 0.0

learning_rate = 5e-4

max_iters = 300000


제공되는 15M 모델을 이어서 훈련한 게 아니라 처음부터 훈련 했습니다.

데이터는 600MB 크기인 30만건 입니다. tinystory en, ko 구성 되었습니다. 

최종 훈련 step 66000: train loss 0.3510, val loss 0.3976

토큰화 크기는 tok1887 입니다.


아래는 실행 결과입니다.


<기본으로 제공되는 가장 빠른 명령어>

OMP_NUM_THREADS=4 ./run out/model.bin -z data/tok1887.bin -n 2048


<s><|en|>

Once upon a time, there was a little dog named Max. Max was a very interesting dog who liked to play with his toys. One day, Max's owner took him for a walk in the park. Max was very excited to go on the swing and play. As they walked, Max saw a big tree. He wanted to climb it, but he didn't know how. Max's owner said, "Max, let's try to climb to the top of the tree." Max tried and tried, but he couldn't do it. Finally, Max got tired and said, "Max, can you help me?" His owner said, "Sure, let's find some honey!" And so, Max and his owner took a big bite. Max felt happy and surprised. His owner said, "Maybe you're sick, Max! You're the most interesting dog in the town!" Max wagged his tail and licked his owner's face. He felt much better and wagged his tail with joy. From that day on, Max always remembered to climb trees and listen to his owner's warnings.

<|ko|>

옛날에 맥스라는 이름의 작은 개가 있었습니다. 맥스는 장난감을 가지고 노는 것을 좋아하는 매우 흥미로운 개였습니다. 어느 날 Max의 주인은 Max를 데리고 공원으로 산책을 나갔습니다. 맥스는 그네를 타고 놀 수 있어서 매우 신났습니다. 그들이 걸어가는 동안 Max는 큰 나무를 보았습니다. 그는 그것을 올라가고 싶었지만 방법을 몰랐습니다. 맥스의 주인은 "맥스야, 나무 위로 올라가자"고 말했다. 맥스는 노력하고 또 노력했지만 할 수 없었습니다. 마침내 Max는 지쳐서 "Max, 도와줄 수 있나요?"라고 말했습니다. 그의 주인은 "물론이죠. 꿀을 찾자!"라고 말했습니다. 그래서 Max와 그의 주인은 크게 한 입 베어 물었습니다. Max는 행복하고 놀랐습니다. 주인은 "아마 아마 아프지 않을 거예요, 맥스! 당신은 마을에서 가장 흥미로운 개예요!"라고 말했습니다. 맥스는 꼬리를 흔들며 주인의 얼굴을 핥았습니다. 그는 기분이 훨씬 나아졌고 기쁨으로 꼬리를 흔들었습니다. 그날 이후로 맥스는 항상 나무에 오르고 주인의 경고를 듣는 것을 기억했습니다.</s>

achieved tok/s: 1343.396226


<s><|en|>

Once upon a time, there was a little girl named Lily. She loved to draw and color. One day, she found a big box of chalk to draw on. But the box was too big for her to draw. She asked her mom for help, but her mom said, "Maybe there's a big fish inside the box?" Lily didn't know what to do, so she asked her mom. Her mom said, "Let's find the chalk and use it to draw prints of things to draw." So, Lily and her mom drew prints of things in the box. They drew a fun picture of the big fish and the toys. Lily was happy because she got to draw a pretty picture with a fun picture.

<|ko|>

옛날 옛적에 릴리라는 어린 소녀가 있었습니다. 그녀는 그림 그리기와 색칠하기를 좋아했습니다. 어느 날, 그녀는 그림을 그릴 큰 상자가 담긴 큰 상자를 발견했습니다. 그러나 그 상자는 그녀가 그릴 수 없는 상자는 그녀에게 열려 있기 때문에 "상자 안에 큰 물고기가 있을 수도 있겠지?"라고 말했습니다. 릴리는 무엇을 해야 할지 몰랐기 때문에 엄마에게 물었습니다. 그녀의 엄마는 "분필을 찾아 사용하면 알려주는 물건을 찾아보자"고 말했습니다. 그래서 릴리와 엄마는 상자에 물건들을 그렸습니다. 그들은 큰 물고기와 장난감 사진을 그렸습니다. 릴리는 재미있는 그림을 사진으로 그릴 수 있어서 행복했습니다.</s>

achieved tok/s: 1980.972516


<s><|en|>

Once upon a time, there was a cheerful little girl named Lily. She loved to watch the stars in the sky. One night, she wanted to see all the stars and the moon. But there was a loud noise. She was scared and ran to her room. Lily's mom told her that the star was just a dream that night. In the morning, Lily woke up and saw that her star had a big smile on her face. She felt brave and wanted to be like her. She said sorry to the stars and planets to go to sleep. The next morning, she woke up and saw that her stars had rocked back up. She was scared and called for her mom. Her mom came and said, "Don't worry, Lily. The star will fix your star and surrender your toys." Lily was happy and proud that she had done the right thing.

<|ko|>

옛날 옛적에 릴리라는 명랑한 소녀가 있었습니다. 그녀는 하늘에서 별을 보는 것을 좋아했습니다. 어느 날 밤, 그녀는 모든 별과 달을 보고 싶어했습니다. 하지만 큰 소리가 나는 것이 있었습니다. 그녀는 겁이 나서 방으로 달려갔습니다. 릴리의 엄마는 그 별이 그날 그 밤이었을 것이라고 말했습니다. 아침에 릴리는 일어나 자신의 별이 얼굴에 환한 미소를 지었다는 것을 알았습니다. 그녀는 용기를 느꼈고 그녀처럼 되고 싶었습니다. 그녀는 별과 행성에 가서 잠을 잤습니다. 다음날 아침, 그녀는 일어나서 자신의 별이 다시 돌아오는 것을 보았습니다. 그녀는 무서워서 엄마를 불렀습니다. 그녀의 엄마가 와서 말했습니다. "걱정하지 마세요, 릴리. 별은 당신의 별을 고치고 당신을 넘어지게 할 것입니다." 릴리는 자신이 옳은 일을 했다는 사실에 행복하고 자랑스러워했습니다.</s>

achieved tok/s: 1622.252747


<gpu 사용할 수 있도록 설정한 명령어>

./runcuda out/model.bin -z data/tok1887.bin -n 2048


<s><|en|>

Once upon a time, there was a little boy named Timmy. Timmy loved to play outside in the snow. One day, Timmy saw a big snowman in the snow. The snowman had a hose near the snowman and was playing in the snow. Timmy wanted to play too, but he didn't know how to behave. His mom saw that Timmy was being selfish and asked him what happened. Timmy told her about the snowman and how he didn't want to be bossy. His mom told him that it's important to behave and be kind to others. So Timmy decided to try the snowman and make him both happy. The next day, Timmy went outside and saw the snowman again. This time, he saw a big, scary dog! Timmy ran back inside and told his mom that he didn't like the snowman. His mom was very sad and said, "Timmy, you have behaved because you might break the snow." Timmy learned that being kind and sharing was better than being bossy.

<|ko|>

옛날 옛적에 티미(Timmy)라는 어린 소년이 있었습니다. 티미는 눈 속에서 밖에서 노는 것을 좋아했습니다. 어느 날 티미는 눈 속에서 큰 눈사람을 보았습니다. 눈사람은 눈사람 근처에 호스를 갖고 놀고 있었고 눈 속에서 놀고 있었습니다. 티미도 놀고 싶었지만 얌전히 행동하는 방법을 몰랐습니다. 그의 엄마는 티미가 이기적이라는 것을 알고 무슨 일이 일어났는지 물었습니다. 티미는 눈사람에 대해 그리고 권위적인 태도를 취하고 싶지 않다고 그녀에게 말했습니다. 그의 엄마는 그에게 행동하고 다른 사람에게 친절하게 대하는 것이 중요하다고 말했습니다. 그래서 티미는 눈사람을 시험해 보고 둘을 모두 행복하게 만들기로 결정했습니다. 다음 날 티미는 밖으로 나가서 눈사람을 다시 보았습니다. 이번에 그는 크고 무서운 개를 보았습니다! 티미는 다시 안으로 달려가 엄마에게 눈사람을 좋아하지 않다고 말했습니다. 그의 엄마는 매우 슬퍼하며 "티미야, 눈이 녹을 수 있으니 얌전히 행동하겠다"고 말했다. 티미는 친절하고 공유하는 것이 권위적인 것보다 낫다는 것을 배웠습니다.</s>

achieved tok/s: 2012.693935


<s><|en|>

Once upon a time, there was a little girl named Lily. She loved to play outside in the snow. One day, she found a big, juicy worm on the snow. She was so happy and wanted to keep it as her pet. Lily put the worm in her mouth and ran outside to play. But the worm was too cold and Lily couldn't move. She asked her friends for help. They were sad because they couldn't keep the worm. But then, Lily had an idea. She remembered that her mom had a small spoonful of worms on the snow. So, she asked her mom to put some special soap on the snow and show it to her friends. They all came over to play in the snow and had so much fun. Lily was happy to have her worm back and to have some worms to play with.

<|ko|>

옛날 옛적에 릴리라는 어린 소녀가 있었습니다. 그녀는 눈 속에서 밖에서 노는 것을 좋아했습니다. 어느 날, 그녀는 눈 속에서 크고 육즙이 많은 벌레를 발견했습니다. 그녀는 너무 기뻐서 그것을 애완동물로 키우고 싶었습니다. 릴리는 벌레를 입에 넣고 밖으로 뛰어나가 놀았습니다. 하지만 벌레가 너무 추워서 릴리는 움직일 수 없었습니다. 그녀는 친구들에게 도움을 요청했습니다. 그들은 벌레를 지킬 수 없어서 슬펐습니다. 그런데 릴리에게 좋은 생각이 떠올랐어요. 그녀는 엄마가 눈 속에 있는 작은 숟가락을 가지고 있다는 것을 기억했습니다. 그래서 그녀는 엄마에게 눈 위에 특별한 비누를 올려 주어 친구들에게 보여달라고 요청했습니다. 그들은 모두 눈밭에서 놀러 왔고 정말 즐거운 시간을 보냈습니다. 릴리는 자신의 벌레를 되찾게 되어 기뻤고 가지고 놀 수 있는 벌레가 있어서 기뻤습니다.</s>

achieved tok/s: 2084.532374


<s><|en|>

Once upon a time, there was a little girl named Lily. She loved to eat beef for dinner every day. One day, Lily's mom asked her to clean up her toys and put them in the trash can. Lily didn't want to clean up, but she knew it was important to keep her room clean. As she was cleaning, she found a shiny rock that she really wanted. She asked her mom if she could have it, but her mom said no because it was too dangerous. Lily felt sad and started to cry. But then, her mom gave her a new kind of beef that was always clean and ready to have it. Lily was happy again and couldn't wait to come back to her mom and clean up her toys and put them away.

<|ko|>

옛날 옛적에 릴리라는 어린 소녀가 있었습니다. 그녀는 매일 저녁으로 쇠고기를 먹는 것을 좋아했습니다. 어느 날, 릴리의 엄마는 릴리에게 장난감을 치워서 쓰레기통에 버리라고 했습니다. 릴리는 청소하고 싶지 않았지만 방을 깨끗하게 유지하는 것이 중요하다는 것을 알고 있었습니다. 그녀는 청소를 하다가 자신이 정말 갖고 싶었던 반짝이는 돌을 발견했습니다. 그녀는 엄마에게 그것을 가질 수 있는지 물었지만 엄마는 너무 위험하기 때문에 안 된다고 말했습니다. 릴리는 슬퍼서 울기 시작했어요. 그런데 그녀의 엄마는 항상 그녀에게 항상 깨끗하고 그것을 먹을 준비가 되어 있는 새로운 종류의 쇠고기를 주었습니다. 릴리는 다시 행복해졌고 빨리 엄마에게 돌아와서 장난감을 치워두고 치워두었습니다.</s>

achieved tok/s: 2127.530364





15M 모델이라 gpu로 돌렸을 경우 2000 tok/s 속도가 꾸준하게 발생하기 때문에 반복해서 수행하여

위와 같이 영어와 한국어가 구절별로 딱 떨어지는 경우

데이터를 쌓도록 하는 작업도 했었습니다.


아마도 4090 24GB 일주일 정도 걸려서 50만 건 데이터를 "생성" 했었습니다. 

하지만... 부주의로 구절별로 잘 나눠진 데이터를 날려 먹은 기억이 나네요.


위 데이터를 이용해서 무한한 쉬운 난이도 영어 학습 앱을 TTS도 붙여서 만들려고 했습니다만... 생각으로 그쳤습니다.


모델을 만들고 6개월이 지난 시점의 저의 학습 결과였습니다.


[파일크기 25MB]