Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions examples/inference/gpt/gpt_dynamic_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def escape_str(s):
print(f' Saving results to {args.output_path}')
with open(args.output_path, "w") as fp:
json.dump(json_results, fp, indent=1)
fp.write("\n") # End file in newline

# Timing results.
stats = torch.cuda.memory_stats()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ async def main(
json_results = throughput_dict
with open(args.output_path, "w") as fp:
json.dump(json_results, fp, indent=4)
fp.write("\n") # End file in newline
else:
print("Results:")
unique_prompt_map = defaultdict(list)
Expand Down
1 change: 1 addition & 0 deletions examples/inference/gpt/gpt_static_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def main():

with open(args.output_path, 'w') as f:
json.dump(results_output, f)
f.write('\n') # End file in newline

# Print unique prompts + outputs.
if torch.distributed.get_rank() == 0:
Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_ai2d.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -31,6 +33,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_chartqa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -28,6 +30,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
1 change: 1 addition & 0 deletions examples/multimodal/evaluation/evaluate_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def convert_to_coco_format(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_infovqa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -28,6 +30,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_mathvista.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json
import re
Expand Down Expand Up @@ -29,6 +31,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
1 change: 1 addition & 0 deletions examples/multimodal/evaluation/evaluate_mmmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def convert_to_mmmu_format(input_path):

with open(output_file_path, "w") as output_file:
json.dump(output, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_ocrbench.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -26,6 +28,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_ocrbench_v2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json
import subprocess
Expand Down Expand Up @@ -30,6 +32,7 @@ def convert_to_ocrbench_v2_format(input_path, groundtruth_path):

with open(output_file_path, "w") as output_file:
json.dump(output, output_file)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_rd_tablebench.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import glob
import json
Expand Down Expand Up @@ -35,6 +37,7 @@ def convert_to_rdtablebench_format(input_path):

with open(output_file_path, "w") as output_file:
json.dump(output, output_file)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_realworldqa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -25,6 +27,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_spdocvqa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -28,6 +30,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_textvqa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -31,6 +33,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_video_motionbench.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -26,6 +28,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_video_mvbench.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand Down Expand Up @@ -25,6 +27,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json

Expand All @@ -24,6 +26,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
3 changes: 3 additions & 0 deletions examples/multimodal/evaluation/evaluate_vqav2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import argparse
import json
from typing import List
Expand Down Expand Up @@ -78,6 +80,7 @@ def merge_input_files(input_path):

with open(output_file_path, "w") as output_file:
json.dump(results, output_file, indent=4, sort_keys=True)
output_file.write("\n") # End file in newline

return output_file_path

Expand Down
9 changes: 6 additions & 3 deletions examples/multimodal/evaluation/mmmu_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

# The following code is adapted from
# https://github.com/MMMU-Benchmark/MMMU/blob/main/mmmu/utils/data_utils.py,
# which is licensed under the Apache License 2.0. More details on the license can be
Expand Down Expand Up @@ -526,10 +528,11 @@ def mmmu_main_eval(output_dict, task_cfg):
)
eval_output_dict[res['question_id']] = pred_ans

json.dump(eval_output_dict, open("validation_mmmu_iter6000_merged.0.53.sorted.json", "w"), indent=4, sort_keys=True)

with open("validation_mmmu_iter6000_merged.0.53.sorted.json", "w") as f:
json.dump(eval_output_dict, f, indent=4, sort_keys=True)
f.write("\n") # End file in newline

x = mmmu_main_eval(eval_output_dict,
task_cfg=tasks['mmmu'])

print(x)
print(x)
1 change: 1 addition & 0 deletions megatron/core/config_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def log_config_to_disk(config, dict_data, prefix='', rank_str=''):
else:
with open(f'{path}.json', 'w') as fp:
json.dump(dict_data, fp, cls=JSONEncoderWithMcoreTypes)
fp.write('\n') # End file in newline


__all__ = ['has_config_logger_enabled', 'log_config_to_disk']
2 changes: 2 additions & 0 deletions megatron/core/dist_checkpointing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def save_config(config: CheckpointingConfig, checkpoint_dir: str):
msc = MultiStorageClientFeature.import_package()
with msc.open(config_path, 'w') as f:
json.dump(asdict(config), f)
f.write('\n') # End file in newline
else:
with open(config_path, 'w') as f:
json.dump(asdict(config), f)
f.write('\n') # End file in newline
1 change: 1 addition & 0 deletions megatron/core/tokenizers/megatron_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def write_metadata(

with open(metadata_path, "w") as f:
json.dump(metadata, f)
f.write("\n") # End file in newline

logger.info(f"Metadata file was sucessfully saved: {metadata_path}.")

Expand Down
2 changes: 2 additions & 0 deletions megatron/rl/rl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def get_environment_rollouts(
'w',
) as f:
json.dump([[r.model_dump() for r in group] for group in rollouts], f)
f.write('\n') # End file in newline

return rollouts

Expand Down Expand Up @@ -1601,6 +1602,7 @@ def evaluate_and_print_results_rl(
'w',
) as f:
json.dump([[r.model_dump() for r in group] for group in dp_eval_results], f)
f.write('\n') # End file in newline


def calculate_grpo_loss(
Expand Down
1 change: 1 addition & 0 deletions megatron/training/ft_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def _update_timeouts(selected_sections, calc_out_of_section):
ft_state = rmon_cli.state_dict()
with open(_ft_state_path, "w") as f:
json.dump(ft_state, f)
f.write("\n") # End file in newline
print_rank_0(f"FT: updated timeouts saved to {_ft_state_path}. {rmon_cli.section_timeouts}")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ def main():

with open(output_path, 'w') as f:
json.dump(output, f, indent=2)
f.write('\n') # End file in newline

logger.info(f"Statistics written to {args.output}")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2023-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import os

os.environ["OPENBLAS_NUM_THREADS"] = "1"
Expand Down Expand Up @@ -76,6 +78,7 @@ def collect_train_test_metrics(
fh,
indent=4,
)
fh.write("\n") # End file in newline


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _persist_baselines(data: Dict[str, Dict[str, float]]) -> None:
BASELINES_PATH.parent.mkdir(parents=True, exist_ok=True)
with BASELINES_PATH.open("w", encoding="utf-8") as fh:
json.dump(data, fh, indent=2, sort_keys=True)
fh.write("\n")
fh.write("\n") # End file in newline


def _serialize_metrics(metrics: Dict[str, float]) -> Dict[str, float]:
Expand Down
3 changes: 2 additions & 1 deletion tools/build_sequences_per_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ def build_sequences_per_dataset(args):

with open(args.path_to_sequences_per_dataset_json, "w") as f:
json.dump(sequence_count_dict, f)
f.write("\n") # End file in newline

print(f"Done! Saving --path-to-sequences-per-dataset file to {args.path_to_sequences_per_dataset_json}")
print(f"Done! Saving --path-to-sequences-per-dataset file to {args.path_to_sequences_per_dataset_json}")
1 change: 1 addition & 0 deletions tools/checkpoint/checkpoint_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ def print_torch_dcp_in_json(torch_dcp_dir, model_weight_prefix="model.module"):
json_file_path = os.path.join(torch_dcp_dir, "param_to_param_group_map.json")
with open(json_file_path, "w") as json_file:
json.dump(serializable_dict, json_file, indent=2)
json_file.write("\n") # End file in newline
click.echo(f"Saved converted param_to_param_group_map to: {json_file_path}")


Expand Down
1 change: 1 addition & 0 deletions tools/checkpoint/loader_llama_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def read_json(path):
def write_json(text, path):
with open(path, "w") as f:
json.dump(text, f)
f.write("\n") # End file in newline


# This conversion is adapted from
Expand Down
Loading