-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADLR/megatron-lm!2517 - Reuse global metadata for first saves
Co-authored-by: Mikołaj Błaż <[email protected]>
- Loading branch information
Showing
10 changed files
with
407 additions
and
12 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
megatron/core/dist_checkpointing/strategies/cached_metadata_filesystem_reader.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. | ||
|
||
""" FS Reader with metadata cached support. """ | ||
|
||
import os | ||
from typing import Union | ||
|
||
from torch.distributed.checkpoint import FileSystemReader, Metadata | ||
|
||
|
||
class CachedMetadataFileSystemReader(FileSystemReader): | ||
""" | ||
Extends FileSystemReader to cache metadata for improved performance. | ||
Attributes: | ||
_cached_metadata (Metadata or None): Cached metadata from the file system. | ||
""" | ||
|
||
def __init__(self, path: Union[str, os.PathLike]) -> None: | ||
""" | ||
Initialize with file system path. | ||
Args: | ||
path (Union[str, os.PathLike]): Path to the checkpoint directory or file. | ||
""" | ||
super().__init__(path=path) | ||
self._cached_metadata = None | ||
|
||
def read_metadata(self) -> Metadata: | ||
""" | ||
Read metadata from file system, caching for subsequent calls. | ||
Returns: | ||
Metadata: Checkpoint metadata. | ||
""" | ||
if self._cached_metadata is None: | ||
self._cached_metadata = super().read_metadata() | ||
return self._cached_metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.