(
# model/data params
model_path: str = "",
seed: int = 42,
train_file: str = "",
eval_file: str = "",
info_file: str = "",
category: str = "",
# wandb params
wandb_project: str = "",
wandb_run_name: str = "",
# training hyperparams
output_dir: str = "",
train_batch_size: int = 32,
eval_batch_size: int = 32,
gradient_accumulation_steps: int = 1,
temperature: float = 1.0,
add_gt: bool = False,
eval_step: float = 0.199,
num_generations: int = 16,
num_train_epochs: int = 1,
learning_rate: float = 1e-6,
beta: float = 0.04,
beam_search: bool = False,
test_during_training: bool = True,
dynamic_sampling: bool = False,
mask_all_zero: bool = False,
sync_ref_model: bool = False,
test_beam: int = 20,
reward_type: str = "rule",
sample_train: bool = False,
ada_path: str = "",
cf_path: str = "",
sid_index_path: str = "",
item_meta_path: str = "",
dapo: bool = False,
gspo: bool = False,
)
| 29 | torch.backends.cudnn.benchmark = False |
| 30 | |
| 31 | def train( |
| 32 | # model/data params |
| 33 | model_path: str = "", |
| 34 | seed: int = 42, |
| 35 | train_file: str = "", |
| 36 | eval_file: str = "", |
| 37 | info_file: str = "", |
| 38 | category: str = "", |
| 39 | |
| 40 | # wandb params |
| 41 | wandb_project: str = "", |
| 42 | wandb_run_name: str = "", |
| 43 | |
| 44 | # training hyperparams |
| 45 | output_dir: str = "", |
| 46 | train_batch_size: int = 32, |
| 47 | eval_batch_size: int = 32, |
| 48 | gradient_accumulation_steps: int = 1, |
| 49 | temperature: float = 1.0, |
| 50 | add_gt: bool = False, |
| 51 | eval_step: float = 0.199, |
| 52 | num_generations: int = 16, |
| 53 | num_train_epochs: int = 1, |
| 54 | learning_rate: float = 1e-6, |
| 55 | beta: float = 0.04, |
| 56 | beam_search: bool = False, |
| 57 | test_during_training: bool = True, |
| 58 | dynamic_sampling: bool = False, |
| 59 | mask_all_zero: bool = False, |
| 60 | sync_ref_model: bool = False, |
| 61 | test_beam: int = 20, |
| 62 | reward_type: str = "rule", |
| 63 | sample_train: bool = False, |
| 64 | ada_path: str = "", |
| 65 | cf_path: str = "", |
| 66 | sid_index_path: str = "", |
| 67 | item_meta_path: str = "", |
| 68 | dapo: bool = False, |
| 69 | gspo: bool = False, |
| 70 | ): |
| 71 | torch.backends.cuda.enable_flash_sdp(False) |
| 72 | torch.backends.cuda.enable_mem_efficient_sdp(False) |
| 73 | set_seed(seed) |
| 74 | |
| 75 | category_dict = {"Industrial_and_Scientific": "industrial and scientific items", "Office_Products": "office products", "Toys_and_Games": "toys and games", "Sports": "sports and outdoors", "Books": "books"} |
| 76 | print(category) |
| 77 | |
| 78 | |
| 79 | with open(info_file, 'r') as f: |
| 80 | info = f.readlines() |
| 81 | # Extract semantic_id (first column) from the format: semantic_id \t item_title \t item_id |
| 82 | item_name = [_.split('\t')[0].strip() for _ in info] |
| 83 | item2id = {name: i for i, name in enumerate(item_name)} |
| 84 | |
| 85 | # Parse semantic IDs for HEPO |
| 86 | def parse_sid(sid): |
| 87 | return re.findall(r'\[.*?\]', sid) |
| 88 |
nothing calls this directly
no test coverage detected