metadata.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from dataclasses import dataclass
  15. from typing import Dict, List, Tuple
  16. @dataclass
  17. class LocalTensorMetadata:
  18. """
  19. The location of a local tensor in the global tensor.
  20. """
  21. global_offset: Tuple[int]
  22. local_shape: Tuple[int]
  23. @dataclass(frozen=True)
  24. class LocalTensorIndex:
  25. """
  26. The identifier of a local tensor.
  27. """
  28. tensor_key: str
  29. global_offset: Tuple[int]
  30. @dataclass
  31. class Metadata:
  32. state_dict_metadata: Dict[str, List[LocalTensorMetadata]] = None
  33. storage_metadata: Dict[LocalTensorIndex, str] = None
  34. flat_mapping: Dict[str, Tuple[str]] = None