Elffuss BraidHub

kikocis/SpatialLM public

main · 5.3 KiBRawPermalink
1# Copyright 2025 HuggingFace Inc. and the LlamaFactory team.
2#
3# This code is inspired by the HuggingFace's transformers library.
4# https://github.com/huggingface/transformers/blob/v4.40.0/examples/pytorch/language-modeling/run_clm.py
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18from dataclasses import asdict, dataclass, field
19from typing import Any, Literal, Optional
20
21
22@dataclass
23class DataArguments:
24 r"""Arguments pertaining to what data we are going to input our model for training and evaluation."""
25
26 template: Optional[str] = field(
27 default=None,
28 metadata={
29 "help": "Which template to use for constructing prompts in training and inference."
30 },
31 )
32 dataset: Optional[str] = field(
33 default=None,
34 metadata={
35 "help": "The name of dataset(s) to use for training. Use commas to separate multiple datasets."
36 },
37 )
38 eval_dataset: Optional[str] = field(
39 default=None,
40 metadata={
41 "help": "The name of dataset(s) to use for evaluation. Use commas to separate multiple datasets."
42 },
43 )
44 dataset_dir: str = field(
45 default="data",
46 metadata={"help": "Path to the folder containing the datasets."},
47 )
48 media_dir: Optional[str] = field(
49 default=None,
50 metadata={
51 "help": "Path to the folder containing the images, videos or audios. Defaults to `dataset_dir`."
52 },
53 )
54 cutoff_len: int = field(
55 default=8192,
56 metadata={"help": "The cutoff length of the tokenized inputs in the dataset."},
57 )
58 overwrite_cache: bool = field(
59 default=False,
60 metadata={"help": "Overwrite the cached training and evaluation sets."},
61 )
62 preprocessing_batch_size: int = field(
63 default=1000,
64 metadata={"help": "The number of examples in one group in pre-processing."},
65 )
66 preprocessing_num_workers: Optional[int] = field(
67 default=None,
68 metadata={"help": "The number of processes to use for the pre-processing."},
69 )
70 max_samples: Optional[int] = field(
71 default=None,
72 metadata={
73 "help": "For debugging purposes, truncate the number of examples for each dataset."
74 },
75 )
76 eval_num_beams: Optional[int] = field(
77 default=None,
78 metadata={
79 "help": "Number of beams to use for evaluation. This argument will be passed to `model.generate`"
80 },
81 )
82 ignore_pad_token_for_loss: bool = field(
83 default=True,
84 metadata={
85 "help": "Whether or not to ignore the tokens corresponding to the pad label in loss computation."
86 },
87 )
88 val_size: float = field(
89 default=0.0,
90 metadata={
91 "help": "Size of the validation set, should be an integer or a float in range `[0,1)`."
92 },
93 )
94 eval_on_each_dataset: bool = field(
95 default=False,
96 metadata={"help": "Whether or not to evaluate on each dataset separately."},
97 )
98 default_system: Optional[str] = field(
99 default=None,
100 metadata={"help": "Override the default system message in the template."},
101 )
102 save_dir: Optional[str] = field(
103 default=None,
104 metadata={
105 "help": (
106 "Path to save or load the preprocessed datasets. "
107 "If save_dir not exists, it will save the preprocessed datasets. "
108 "If save_dir exists, it will load the preprocessed datasets."
109 )
110 },
111 )
112 data_shared_file_system: bool = field(
113 default=False,
114 metadata={
115 "help": "Whether or not to use a shared file system for the datasets."
116 },
117 )
118 num_bins: int = field(
119 default=1280,
120 metadata={"help": "The number of bins for point cloud quantization."},
121 )
122 do_augmentation: bool = field(
123 default=False,
124 metadata={"help": "Whether or not to do data augmentation."},
125 )
126 random_rotation: bool = field(
127 default=False,
128 metadata={"help": "Whether or not to do non axis-aligned random rotation."},
129 )
130
131 def __post_init__(self):
132 def split_arg(arg):
133 if isinstance(arg, str):
134 return [item.strip() for item in arg.split(",")]
135 return arg
136
137 self.dataset = split_arg(self.dataset)
138 self.eval_dataset = split_arg(self.eval_dataset)
139
140 if self.media_dir is None:
141 self.media_dir = self.dataset_dir
142
143 if self.dataset is None and self.val_size > 1e-6:
144 raise ValueError("Cannot specify `val_size` if `dataset` is None.")
145
146 if self.eval_dataset is not None and self.val_size > 1e-6:
147 raise ValueError("Cannot specify `val_size` if `eval_dataset` is not None.")
148
149 def to_dict(self) -> dict[str, Any]:
150 return asdict(self)