diff --git a/examples/inference/gpt/gpt_dynamic_inference.py b/examples/inference/gpt/gpt_dynamic_inference.py index 2582f57e13e..55979845512 100644 --- a/examples/inference/gpt/gpt_dynamic_inference.py +++ b/examples/inference/gpt/gpt_dynamic_inference.py @@ -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() diff --git a/examples/inference/gpt/gpt_dynamic_inference_with_coordinator.py b/examples/inference/gpt/gpt_dynamic_inference_with_coordinator.py index 536f533eccd..072239c0ab3 100644 --- a/examples/inference/gpt/gpt_dynamic_inference_with_coordinator.py +++ b/examples/inference/gpt/gpt_dynamic_inference_with_coordinator.py @@ -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) diff --git a/examples/inference/gpt/gpt_static_inference.py b/examples/inference/gpt/gpt_static_inference.py index 17cf7c53b05..4c820fd06a3 100644 --- a/examples/inference/gpt/gpt_static_inference.py +++ b/examples/inference/gpt/gpt_static_inference.py @@ -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: diff --git a/examples/multimodal/evaluation/evaluate_ai2d.py b/examples/multimodal/evaluation/evaluate_ai2d.py index 01ff4e8f48f..8f98b8e871b 100644 --- a/examples/multimodal/evaluation/evaluate_ai2d.py +++ b/examples/multimodal/evaluation/evaluate_ai2d.py @@ -1,3 +1,5 @@ +# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_chartqa.py b/examples/multimodal/evaluation/evaluate_chartqa.py index 7fbddf0204f..8c69e7b2086 100644 --- a/examples/multimodal/evaluation/evaluate_chartqa.py +++ b/examples/multimodal/evaluation/evaluate_chartqa.py @@ -1,3 +1,5 @@ +# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_coco.py b/examples/multimodal/evaluation/evaluate_coco.py index 50031f3a5c4..1d92cc3c5f6 100644 --- a/examples/multimodal/evaluation/evaluate_coco.py +++ b/examples/multimodal/evaluation/evaluate_coco.py @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_infovqa.py b/examples/multimodal/evaluation/evaluate_infovqa.py index ca327ab2b0d..87994ec4952 100644 --- a/examples/multimodal/evaluation/evaluate_infovqa.py +++ b/examples/multimodal/evaluation/evaluate_infovqa.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_mathvista.py b/examples/multimodal/evaluation/evaluate_mathvista.py index cb6b2ebd236..c49822006ee 100644 --- a/examples/multimodal/evaluation/evaluate_mathvista.py +++ b/examples/multimodal/evaluation/evaluate_mathvista.py @@ -1,3 +1,5 @@ +# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json import re @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_mmmu.py b/examples/multimodal/evaluation/evaluate_mmmu.py index 2bdc2ebbdc5..cbe7b21980f 100644 --- a/examples/multimodal/evaluation/evaluate_mmmu.py +++ b/examples/multimodal/evaluation/evaluate_mmmu.py @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_ocrbench.py b/examples/multimodal/evaluation/evaluate_ocrbench.py index b43d195494f..267ec4cd96c 100644 --- a/examples/multimodal/evaluation/evaluate_ocrbench.py +++ b/examples/multimodal/evaluation/evaluate_ocrbench.py @@ -1,3 +1,5 @@ +# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_ocrbench_v2.py b/examples/multimodal/evaluation/evaluate_ocrbench_v2.py index 660f4ecbea7..737eafc7dd3 100644 --- a/examples/multimodal/evaluation/evaluate_ocrbench_v2.py +++ b/examples/multimodal/evaluation/evaluate_ocrbench_v2.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json import subprocess @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_rd_tablebench.py b/examples/multimodal/evaluation/evaluate_rd_tablebench.py index 588c1927799..9b17e0b56cb 100644 --- a/examples/multimodal/evaluation/evaluate_rd_tablebench.py +++ b/examples/multimodal/evaluation/evaluate_rd_tablebench.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import glob import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_realworldqa.py b/examples/multimodal/evaluation/evaluate_realworldqa.py index 6ef78d047e3..9a40e9bbc5f 100644 --- a/examples/multimodal/evaluation/evaluate_realworldqa.py +++ b/examples/multimodal/evaluation/evaluate_realworldqa.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_spdocvqa.py b/examples/multimodal/evaluation/evaluate_spdocvqa.py index 57a5c237af5..1f6862dd675 100644 --- a/examples/multimodal/evaluation/evaluate_spdocvqa.py +++ b/examples/multimodal/evaluation/evaluate_spdocvqa.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_textvqa.py b/examples/multimodal/evaluation/evaluate_textvqa.py index e3647db3a24..65e31dc9660 100644 --- a/examples/multimodal/evaluation/evaluate_textvqa.py +++ b/examples/multimodal/evaluation/evaluate_textvqa.py @@ -1,3 +1,5 @@ +# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_video_motionbench.py b/examples/multimodal/evaluation/evaluate_video_motionbench.py index 7d6db0354e2..a858d0bad36 100644 --- a/examples/multimodal/evaluation/evaluate_video_motionbench.py +++ b/examples/multimodal/evaluation/evaluate_video_motionbench.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_video_mvbench.py b/examples/multimodal/evaluation/evaluate_video_mvbench.py index 0efcdbedb14..3a0f2fd8618 100644 --- a/examples/multimodal/evaluation/evaluate_video_mvbench.py +++ b/examples/multimodal/evaluation/evaluate_video_mvbench.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_video_phys_game_bench.py b/examples/multimodal/evaluation/evaluate_video_phys_game_bench.py index feb4c558120..22caec5d548 100644 --- a/examples/multimodal/evaluation/evaluate_video_phys_game_bench.py +++ b/examples/multimodal/evaluation/evaluate_video_phys_game_bench.py @@ -1,3 +1,5 @@ +# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json @@ -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 diff --git a/examples/multimodal/evaluation/evaluate_vqav2.py b/examples/multimodal/evaluation/evaluate_vqav2.py index 9789e30379b..156f115db5a 100644 --- a/examples/multimodal/evaluation/evaluate_vqav2.py +++ b/examples/multimodal/evaluation/evaluate_vqav2.py @@ -1,3 +1,5 @@ +# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import argparse import json from typing import List @@ -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 diff --git a/examples/multimodal/evaluation/mmmu_utils.py b/examples/multimodal/evaluation/mmmu_utils.py index 61a876b067b..d7cf2e5b26e 100644 --- a/examples/multimodal/evaluation/mmmu_utils.py +++ b/examples/multimodal/evaluation/mmmu_utils.py @@ -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 @@ -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) \ No newline at end of file + print(x) diff --git a/megatron/core/config_logger.py b/megatron/core/config_logger.py index bee2be09205..c21535e05e8 100644 --- a/megatron/core/config_logger.py +++ b/megatron/core/config_logger.py @@ -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'] diff --git a/megatron/core/dist_checkpointing/core.py b/megatron/core/dist_checkpointing/core.py index 164aec1ca52..42aba89ea2d 100644 --- a/megatron/core/dist_checkpointing/core.py +++ b/megatron/core/dist_checkpointing/core.py @@ -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 diff --git a/megatron/core/tokenizers/megatron_tokenizer.py b/megatron/core/tokenizers/megatron_tokenizer.py index 31694d91af0..dd5f1d1ab41 100644 --- a/megatron/core/tokenizers/megatron_tokenizer.py +++ b/megatron/core/tokenizers/megatron_tokenizer.py @@ -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}.") diff --git a/megatron/rl/rl_utils.py b/megatron/rl/rl_utils.py index 46436add1da..55cd1b9fe54 100644 --- a/megatron/rl/rl_utils.py +++ b/megatron/rl/rl_utils.py @@ -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 @@ -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( diff --git a/megatron/training/ft_integration.py b/megatron/training/ft_integration.py index f3532e75639..e5782811a5d 100644 --- a/megatron/training/ft_integration.py +++ b/megatron/training/ft_integration.py @@ -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}") diff --git a/tests/functional_tests/python_test_utils/compute_golden_statistics.py b/tests/functional_tests/python_test_utils/compute_golden_statistics.py index d4863fa9476..ecc159c755f 100644 --- a/tests/functional_tests/python_test_utils/compute_golden_statistics.py +++ b/tests/functional_tests/python_test_utils/compute_golden_statistics.py @@ -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}") diff --git a/tests/functional_tests/python_test_utils/get_test_results_from_tensorboard_logs.py b/tests/functional_tests/python_test_utils/get_test_results_from_tensorboard_logs.py index 7b74a6879ad..1da044f07b0 100644 --- a/tests/functional_tests/python_test_utils/get_test_results_from_tensorboard_logs.py +++ b/tests/functional_tests/python_test_utils/get_test_results_from_tensorboard_logs.py @@ -1,3 +1,5 @@ +# Copyright (c) 2023-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + import os os.environ["OPENBLAS_NUM_THREADS"] = "1" @@ -76,6 +78,7 @@ def collect_train_test_metrics( fh, indent=4, ) + fh.write("\n") # End file in newline if __name__ == "__main__": diff --git a/tests/functional_tests/test_cases/common/moe_perf/__main__.py b/tests/functional_tests/test_cases/common/moe_perf/__main__.py index ace44c7ca4f..9a89bdef5fb 100644 --- a/tests/functional_tests/test_cases/common/moe_perf/__main__.py +++ b/tests/functional_tests/test_cases/common/moe_perf/__main__.py @@ -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]: diff --git a/tools/build_sequences_per_dataset.py b/tools/build_sequences_per_dataset.py index e2787dd6434..cd955c2f285 100644 --- a/tools/build_sequences_per_dataset.py +++ b/tools/build_sequences_per_dataset.py @@ -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}") \ No newline at end of file + print(f"Done! Saving --path-to-sequences-per-dataset file to {args.path_to_sequences_per_dataset_json}") diff --git a/tools/checkpoint/checkpoint_inspector.py b/tools/checkpoint/checkpoint_inspector.py index 3d03f4db959..a5e98bbeb53 100644 --- a/tools/checkpoint/checkpoint_inspector.py +++ b/tools/checkpoint/checkpoint_inspector.py @@ -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}") diff --git a/tools/checkpoint/loader_llama_mistral.py b/tools/checkpoint/loader_llama_mistral.py index 3c3a1b610a1..287e3045305 100644 --- a/tools/checkpoint/loader_llama_mistral.py +++ b/tools/checkpoint/loader_llama_mistral.py @@ -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