Skip to content

Commit 899add0

Browse files
enable to set save path
1 parent bcb70f8 commit 899add0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

utils/batch_viewer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def view_data(
1818
args,
1919
neox_args,
2020
batch_fn: callable = None,
21+
save_path: str = None,
2122
):
2223
# fake MPU setup (needed to init dataloader without actual GPUs or parallelism)
2324
mpu.mock_model_parallel()
@@ -37,12 +38,14 @@ def view_data(
3738

3839
if args.mode == "save":
3940
# save full batches for each step in the range (WARNING: this may consume lots of storage!)
40-
np.save(f"./dump_data/batch{i}_bs{neox_args.train_micro_batch_size_per_gpu}", batch)
41+
filename = f"batch{i}_bs{neox_args.train_micro_batch_size_per_gpu}"
42+
np.save(os.path.join(save_path, filename), batch)
4143
elif args.mode == "custom":
4244
# dump user_defined statistic to a jsonl file (save_fn must return a dict)
4345
log = batch_fn(batch, i)
4446

45-
with open("./dump_data/stats.jsonl", "w+") as f:
47+
filename = "stats.jsonl"
48+
with open(os.path.join(save_path, filename), "w+") as f:
4649
f.write(json.dumps(log) + "\n")
4750
else:
4851
raise ValueError(f'mode={mode} not acceptable--please pass either "save" or "custom" !')
@@ -74,6 +77,12 @@ def view_data(
7477
choices=["save", "custom"],
7578
help="Choose mode: 'save' to log all batches, and 'custom' to use user-defined statistic"
7679
)
80+
parser.add_argument(
81+
"--save_path",
82+
type=str,
83+
default=0,
84+
help="Save path for files"
85+
)
7786
args = parser.parse_known_args()[0]
7887

7988
# init neox args
@@ -86,10 +95,11 @@ def save_fn(batch: np.array, iteration: int):
8695
# define your own logic here
8796
return {"iteration": iteration, "text": None}
8897

98+
os.makedirs(args.save_path, exist_ok=True)
8999

90100
view_data(
91101
args,
92102
neox_args,
93103
batch_fn=save_fn,
104+
save_path=args.save_path,
94105
)
95-

0 commit comments

Comments
 (0)