class_docstr: Represents the WeiGit repo for tracking neural network weights and their versions.
  
  A WeiGit repo is like a git repo. It is a dir, in which a .wgit dir exists to keep
  track of the content.
  
  Args:
      parent_dir (Path, str):
          Parent dir in which to make or to load a .wgit dir.
          Default: "", which means CWD.
      init (bool, optional):
          - If ``True``, initializes a new WeiGit repo in the parent_dir. Initialization
            creates a `.wgit` directory within the <parent_dir>, triggers an initialization.
            of a sha1_store in the ./<parent_dir>/.wgit directory, and makes the
            ./<parent_dir>/.wgit a git repository through git initialization.
          - If ``False``, a new WeiGit repo is not initialized and the existing repo is
            wrapped, populating the `_wgit_parent` and other internal attributes.
          - Default: False
class_docstr_tok: ["Represents","the","WeiGit","repo","for","tracking","neural","network","weights","and","their","versions",".","A","WeiGit","repo","is","like","a","git","repo",".","It","is","a","dir",",","in","which","a",".wgit","dir","exists","to","keep","track","of","the","content",".","Args",":","parent_dir","(","Path",",","str",")",":","Parent","dir","in","which","to","make","or","to","load","a",".wgit","dir",".","Default",":","``","''",",","which","means","CWD",".","init","(","bool",",","optional",")",":","-","If","``","True","``",",","initializes","a","new","WeiGit","repo","in","the","parent_dir",".","Initialization","creates","a","`",".wgit","`","directory","within","the","<","parent_dir",">",",","triggers","an","initialization",".","of","a","sha1_store","in","the",".\/","<","parent_dir",">","\/.wgit","directory",",","and","makes","the",".\/","<","parent_dir",">","\/.wgit","a","git","repository","through","git","initialization",".","-","If","``","False","``",",","a","new","WeiGit","repo","is","not","initialized","and","the","existing","repo","is","wrapped",",","populating","the","`","_wgit_parent","`","and","other","internal","attributes",".","-","Default",":","False"]
docstr: Add a file to the wgit repo.
  
  This could a new file or a modified file. Adding an unmodified, existing file
  is allowed but it is a noop.
  
  Args:
      in_file_path (str):
          Path to the file to be added.
      per_tensor (bool, optional):
          Add a file in a per-tensor fashion. This enables more deduplication
          due to tensors being identical. Deduplication cannot be disabled
          completely because we use a content addressable SHA1_Store class.
          Default: True
      gzip (bool, optional):
          Enable gzip based lossless compression on the object being added.
          Default: True
      sparsify (bool, optional):
          Enable sparsify for the tensors, which is going to modify the values
          for all or some tensors, i.e. lossy compression.
          Default: False
      sparsify_policy (Any):
          TODO (Min): need to add a callback function to control which tensors
                      and how to sparsify.
          Default: None
  
  Returns:
      (Dict, optional)
          None if the content is added but not modified with lossy compression.
          Otherwise, returns a state_dict that contains the modified Tensors to
          be loaded back into the model, which means the tensors are dense, not
          SST and DST tensors.
docstr_tok: ["Add","a","file","to","the","wgit","repo",".","This","could","a","new","file","or","a","modified","file",".","Adding","an","unmodified",",","existing","file","is","allowed","but","it","is","a","noop",".","Args",":","in_file_path","(","str",")",":","Path","to","the","file","to","be","added",".","per_tensor","(","bool",",","optional",")",":","Add","a","file","in","a","per-tensor","fashion",".","This","enables","more","deduplication","due","to","tensors","being","identical",".","Deduplication","can","not","be","disabled","completely","because","we","use","a","content","addressable","SHA1_Store","class",".","Default",":","True","gzip","(","bool",",","optional",")",":","Enable","gzip","based","lossless","compression","on","the","object","being","added",".","Default",":","True","sparsify","(","bool",",","optional",")",":","Enable","sparsify","for","the","tensors",",","which","is","going","to","modify","the","values","for","all","or","some","tensors",",","i.e",".","lossy","compression",".","Default",":","False","sparsify_policy","(","Any",")",":","TODO","(","Min",")",":","need","to","add","a","callback","function","to","control","which","tensors","and","how","to","sparsify",".","Default",":","None","Returns",":","(","Dict",",","optional",")","None","if","the","content","is","added","but","not","modified","with","lossy","compression",".","Otherwise",",","returns","a","state_dict","that","contains","the","modified","Tensors","to","be","loaded","back","into","the","model",",","which","means","the","tensors","are","dense",",","not","SST","and","DST","tensors","."]
code: def add(
      self,
      in_file_path: str,
      per_tensor: bool = True,
      gzip: bool = True,
      sparsify: bool = False,
      sparsify_policy: Any = None,
  ) -> Optional[Dict[Any, Any]]:
      """Add a file to the wgit repo.
  
      This could a new file or a modified file. Adding an unmodified, existing file
      is allowed but it is a noop.
  
      Args:
          in_file_path (str):
              Path to the file to be added.
          per_tensor (bool, optional):
              Add a file in a per-tensor fashion. This enables more deduplication
              due to tensors being identical. Deduplication cannot be disabled
              completely because we use a content addressable SHA1_Store class.
              Default: True
          gzip (bool, optional):
              Enable gzip based lossless compression on the object being added.
              Default: True
          sparsify (bool, optional):
              Enable sparsify for the tensors, which is going to modify the values
              for all or some tensors, i.e. lossy compression.
              Default: False
          sparsify_policy (Any):
              TODO (Min): need to add a callback function to control which tensors
                          and how to sparsify.
              Default: None
  
      Returns:
          (Dict, optional)
              None if the content is added but not modified with lossy compression.
              Otherwise, returns a state_dict that contains the modified Tensors to
              be loaded back into the model, which means the tensors are dense, not
              SST and DST tensors.
      """
      self._sanity_check()
  
      if sparsify and not per_tensor:
          raise ValueError(
              "Only support sparsity when per_tensor is true"
          )
  
      # Create the corresponding metadata file or load it if the file is
      # not a newly added file.
      file_path = Path(in_file_path)
      rel_file_path = self._rel_file_path(file_path)
      metadata_file = self._process_metadata_file(rel_file_path)
  
      # Add the file to the sha1_store.
      ret_state_dict = None
      file_path_or_state_dict: Union[Path, Dict] = file_path
      # TODO (Min): We don't add parent sha1 tracking to sha1 store due to
      #             de-duplication & dependency tracking can create cycles.
      #             We need to figure out a way to handle deletion.
      # TODO (Min): We don't detect changes and compute delta on a modified file
      #             yet. Need to figure out a method for delta tracking.
      if per_tensor:
  
          def fn(element: Any, names: List[str]) -> Any:
              """Callback on each leaf object for _recursive_apply_to_elements below."""
              if isinstance(element, Tensor):
                  if sparsify:
                      # TODO (Min): here we will optionally do SST/DST and add those
                      #             tensors with sparsity.
                      #             Remember to update ret_state_dict
                      raise NotImplementedError()
                  sha1 = self._sha1_store.add(
                      element, compress=gzip, name=".".join(names)
                  )
                  return _SHA1_Tensor(is_dense=True, dense_sha1=sha1)
              else:
                  return element
  
          state_dict = torch.load(file_path)
          ret_state_dict = copy.deepcopy(
              state_dict
          )  # This is only a temporary addition for testing.
          _recursive_apply_to_elements(state_dict, fn, [])
          file_path_or_state_dict = state_dict
  
      # Add this top-level object.
      sha1 = self._sha1_store.add(
          file_path_or_state_dict, compress=gzip
      )
  
      # write metadata to the metadata-file
      self._write_metadata(metadata_file, file_path, sha1)
      self._pygit.add()  # add to the .wgit/.git repo
  
      return ret_state_dict
  
imports: import copy
  from dataclasses import dataclass
  from enum import Enum
  import json
  from pathlib import Path
  import sys
  from typing import Any, Dict, List, Optional, Union
  import torch
  from torch import Tensor
  from .pygit import PyGit
  from .sha1_store import SHA1_Store
label_desc: Use image node_id 6 for calling the Repo obj's underlying member method code with example usage: obj.add(in_file_path, per_tensor, gzip, sparsify, sparsify_policy) and returns: ret_state_dict, _SHA1_Tensor, element