--- library_name: transformers tags: - llama-factory license: other license_name: glm-4 license_link: https://huggingface.co/THUDM/glm-4v-9b/blob/main/LICENSE datasets: - jojo0217/korean_rlhf_dataset - jojo0217/korean_safe_conversation - HAERAE-HUB/qarv-instruct-ko - HAERAE-HUB/Korean-Human-Judgements - HAERAE-HUB/K2-Feedback - changpt/ko-lima-vicuna language: - ko pipeline_tag: text-generation --- ## Model - base model: [THUDM/glm-4v-9b](https://huggingface.co/THUDM/glm-4v-9b) ## Dataset - [jojo0217/korean_rlhf_dataset](https://huggingface.co/datasets/jojo0217/korean_rlhf_dataset) - [jojo0217/korean_safe_conversation](https://huggingface.co/datasets/jojo0217/korean_safe_conversation) - [HAERAE-HUB/qarv-instruct-ko](https://huggingface.co/datasets/HAERAE-HUB/qarv-instruct-ko) - [HAERAE-HUB/Korean-Human-Judgements](https://huggingface.co/datasets/HAERAE-HUB/Korean-Human-Judgements) - [HAERAE-HUB/K2-Feedback](https://huggingface.co/datasets/HAERAE-HUB/K2-Feedback) - [changpt/ko-lima-vicuna](https://huggingface.co/datasets/changpt/ko-lima-vicuna) ## Load Model Use the following Python code to load the model: ```python3 from transformers import AutoTokenizer, AutoModelForCausalLM path = 'youjunhyeok/glm4-9b-ko-v1' model = AutoModelForCausalLM.from_pretrained(path, trust_remote_code=True) tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True) model.to('cuda') ``` ## Chat ```python3 def chat(message): messages = [ {"role": "system", "content": "당신은 인공지능 어시스턴트입니다. 친절하고 정확한 답변을 해주세요."}, {"role": "user", "content": message}, ] input_ids = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_tensors="pt" ).to(model.device) terminators = [ tokenizer.eos_token_id, ] outputs = model.generate( input_ids, max_new_tokens=512, eos_token_id=terminators, do_sample=True, temperature=0.9, top_p=0.95, ) response = outputs[0][input_ids.shape[-1]:] print(tokenizer.decode(response, skip_special_tokens=True)) chat('3차 세계대전이 일어난다면 어떻게 될 지 상상해서 알려줘') ``` ## Output ``` 3차 세계대전은 역사적으로 상상하기 힘들고, 사실상 존재하지 않은 이야기입니다. 만약 이런 일이 일어나게 되었다면, 전 세계가 파괴되고 수많은 사람들이 죽을 것입니다. 전쟁은 승자가 없으며, 상황의 복잡성을 고려할 때 더욱 그렇습니다. 세계는 2차 세계대전에서 수많은 전쟁의 원인을 배워야 했고, 히틀러를 필두로 한 나치 독일이 유럽을 지배했던 과거의 절망을 겪었습니다. 이는 세계 2차 전쟁 이후 국제 평화를 유지하기 위한 많은 노력의 시작이었습니다. 이러한 노력의 일환으로, 유엔이 설립되었고, 국제 평화와 안보를 책임진다면, 3차 세계대전은 전례 없는 규모의 전쟁이 될 것입니다. 유엔과 같은 국제기구가 3차 세계대전을 막기 위해 노력할 것이고, 모든 나라가 평화로운 해결을 위해 협력할 것입니다. 역사적으로 전쟁은 절대적으로 없어지지 않았지만, 국제 협력과 연대가 가능하다고 믿습니다. ``` ## BenchMark (vs Base Model) ### youjunhyeok/glm4-9b-ko-v1 | | acc,none | acc_stderr,none | acc_norm,none | acc_norm_stderr,none | alias | |:--------------|-----------:|------------------:|----------------:|-----------------------:|:--------------| | ko_truthfulqa | 0.29131 | 0.015906 | nan | nan | ko_truthfulqa | | ko_hellaswag | 0.381398 | 0.00484737 | 0.486059 | 0.00498784 | ko_hellaswag | | ko_common_gen | 0.856491 | 0.0089572 | 0.856491 | 0.0089572 | ko_common_gen | | ko_arc_easy | 0.330205 | 0.0137431 | 0.392491 | 0.0142696 | ko_arc_easy | | openbookqa | 0.352 | 0.02138 | 0.45 | 0.0222709 | openbookqa | | hellaswag | 0.615515 | 0.00485479 | 0.801036 | 0.00398405 | hellaswag | | boolq | 0.86422 | 0.00599132 | nan | nan | boolq | | arc_easy | 0.824916 | 0.00779824 | 0.79335 | 0.00830841 | arc_easy | | arc_challenge | 0.532423 | 0.0145806 | 0.551195 | 0.0145346 | arc_challenge | | | 0 | 5 | |:----------------------------|---------:|---------:| | kobest_boolq (macro_f1) | 0.351189 | 0.905978 | | kobest_copa (macro_f1) | 0.645113 | 0.67963 | | kobest_hellaswag (macro_f1) | 0.454822 | 0.479868 | | kobest_sentineg (macro_f1) | 0.599628 | 0.926861 | ### THUDM/glm-4-9b-chat | | acc,none | acc_stderr,none | acc_norm,none | acc_norm_stderr,none | alias | |:--------------|-----------:|------------------:|----------------:|-----------------------:|:--------------| | ko_truthfulqa | 0.334149 | 0.0165125 | nan | nan | ko_truthfulqa | | ko_hellaswag | 0.379805 | 0.00484346 | 0.475901 | 0.00498398 | ko_hellaswag | | ko_common_gen | 0.816699 | 0.00988516 | 0.816699 | 0.00988516 | ko_common_gen | | ko_arc_easy | 0.360068 | 0.0140275 | 0.406143 | 0.0143517 | ko_arc_easy | | openbookqa | 0.354 | 0.0214076 | 0.468 | 0.0223372 | openbookqa | | hellaswag | 0.618901 | 0.00484664 | 0.806413 | 0.00394301 | hellaswag | | boolq | 0.868196 | 0.00591652 | nan | nan | boolq | | arc_easy | 0.824074 | 0.00781297 | 0.800084 | 0.00820653 | arc_easy | | arc_challenge | 0.551195 | 0.0145346 | 0.576792 | 0.014438 | arc_challenge | | | 0 | 5 | |:----------------------------|---------:|---------:| | kobest_boolq (macro_f1) | 0.351527 | 0.696896 | | kobest_copa (macro_f1) | 0.518982 | 0.5104 | | kobest_hellaswag (macro_f1) | 0.37683 | 0.384024 | | kobest_sentineg (macro_f1) | 0.375372 | 0.663805 | ## Llama_factory Train Config {data_dir}, {dataset_name}, {output_dir} is variable ``` cutoff_len: 2048 dataset: rlhf_dataset,safe_conversation,qarv-instruct-ko,korean-human-judgements,k2-feedback,ko_lima_vicuna dataset_dir: /home/work/dweax/train/dataset ddp_timeout: 180000000 do_train: true eval_steps: 100 eval_strategy: steps finetuning_type: lora flash_attn: auto fp16: true gradient_accumulation_steps: 4 include_num_input_tokens_seen: true learning_rate: 5.0e-05 logging_steps: 5 lora_alpha: 16 lora_dropout: 0.05 lora_rank: 16 lora_target: all loraplus_lr_ratio: 1 lr_scheduler_type: cosine max_grad_norm: 1.0 max_samples: 20000 model_name_or_path: THUDM/glm-4-9b num_train_epochs: 2.0 optim: adamw_torch output_dir: saves/GLM-4-9B/lora/glm4-alpha-v1 packing: true per_device_eval_batch_size: 4 per_device_train_batch_size: 4 plot_loss: true preprocessing_num_workers: 16 quantization_bit: 4 report_to: all save_steps: 100 stage: sft template: glm4 val_size: 0.01 warmup_steps: 250 ```