class_docstr: Struct with metadata about a script execution.
class_docstr_tok: ["Struct","with","metadata","about","a","script","execution","."]
docstr: Update this metadata with current machine information.
  
  Used in sharding, to create a machine-specific metadata, while retaining the process
  timestamp and id.
docstr_tok: ["Update","this","metadata","with","current","machine","information",".","Used","in","sharding",",","to","create","a","machine-specific","metadata",",","while","retaining","the","process","timestamp","and","id","."]
code: def for_shard(self) -> "BenchmarkMetadata":
      """
      Update this metadata with current machine information.
  
      Used in sharding, to create a machine-specific metadata, while retaining the process
      timestamp and id.
      """
      new_metadata = BenchmarkMetadata.create(self.suite_name)
      kwargs = asdict(new_metadata)
      keep_new_fields = [
          "argv",
          "user",
          "hostname",
          "ram",
          "cpu_name",
          "cpu_count",
          "cpu_frequency",
          "gpu_names",
      ]
      keep_old_fields = ["timestamp", "run_id"]
      must_match_fields = [
          "suite_name",
          "py_ver",
          "tf_ver",
          "np_ver",
          "git_branch_name",
          "git_commit",
      ]
      for field in keep_old_fields:
          del kwargs[field]
      for field in must_match_fields:
          assert getattr(self, field) == kwargs[field], (
              f"Field {field} must match between new and old metadata."
              f" Found {getattr(self, field)} and {kwargs[field]}"
          )
          del kwargs[field]
      assert keep_new_fields == list(kwargs)
  
      return replace(self, **kwargs)
  
imports: import getpass
  import sys
  from dataclasses import asdict, dataclass, replace
  from datetime import datetime
  from pathlib import Path
  from platform import python_version
  from socket import gethostname
  from typing import Any, Mapping, Sequence, Tuple
  import numpy
  import psutil
  import tensorflow
  from cpuinfo import get_cpu_info
  from git.exc import InvalidGitRepositoryError
  from git.repo import Repo
  from tensorflow.python.client import device_lib
label_desc: Use image node_id 2 for calling the BenchmarkMetadata obj's underlying member method code with example usage: obj.for_shard() and returns: replace