Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modifiy cache path rule for pretrain datasets to fix bug #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
from loguru import logger
import os
import time
from os.path import join
import torch
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training
Expand Down Expand Up @@ -140,15 +141,17 @@ def group_texts(examples):
logger.info(f'Loading file: {file}')
file_name = os.path.basename(file)
file_name = file_name.replace('.jsonl', '')
cache_path = os.path.join(cache_dir, file_name)

mtime=time.strftime("%Y%m%d%H%M%S", time.localtime(os.stat(file).st_mtime))
cache_path = os.path.join(cache_dir,tokenizer.name_or_path,file_name,mtime)
os.makedirs(cache_path, exist_ok=True)

try:
processed_dataset = datasets.load_from_disk(cache_path, keep_in_memory=False)
logger.info(f'Finished loading datasets-{file_name} from cache')
except Exception:
tmp_cache_path = join(cache_path, 'tmp') # 临时缓存目录,会被自动删除
logger.info(f'There is no cache of file {file_name}, start preprocessing...')
logger.info(f'There is no cache of file {file_name} modified @ {mtime} for tokenizer {tokenizer.name_or_path}, start preprocessing...')
raw_dataset = load_dataset("json", data_files=file, cache_dir=tmp_cache_path, keep_in_memory=False)
tokenized_dataset = raw_dataset.map(
tokenize_function,
Expand Down