class_docstr: Base class for your neural network models.
  
  Example usage::
  
      import numpy as np
      from singa import opt
      from singa import tensor
      from singa import device
      from singa import autograd
      from singa import layer
      from singa import model
  
      class MyModel(model.Model):
          def __init__(self):
              super(MyModel, self).__init__()
  
              self.softmax_cross_entropy = layer.SoftMaxCrossEntropy()
              self.conv1 = layer.Conv2d(1, 20, 5, padding=0)
              self.conv2 = layer.Conv2d(20, 50, 5, padding=0)
              self.sgd = opt.SGD(lr=0.01)
  
          def forward(self, x):
              y = self.conv1(x)
              y = self.conv2(y)
              return y
  
          def train_one_batch(self, x, y):
              out = self.forward(x)
              loss = self.softmax_cross_entropy(out, y)
              self.sgd(loss)
              return out, loss
docstr: Save states.
  
  Args:
      fpath: output file path (without the extension)
      aux_states(dict): values are standard data types or Tensor,
                        e.g., epoch ID, learning rate, optimizer states
docstr_tok: ["Save","states",".","Args",":","fpath",":","output","file","path","(","without","the","extension",")","aux_states","(","dict",")",":","values","are","standard","data","types","or","Tensor",",","e.g.",",","epoch","ID",",","learning","rate",",","optimizer","states"]
code: def save_states(self, fpath, aux_states={}):
      """Save states.
  
      Args:
          fpath: output file path (without the extension)
          aux_states(dict): values are standard data types or Tensor,
                            e.g., epoch ID, learning rate, optimizer states
      """
      assert not os.path.isfile(fpath), (
          "Failed to save states, %s is already existed." % fpath
      )
  
      states = self.get_states()
  
      # save states data and attr
      tensor_dict = {}
      states_attr = {}
      for k, v in states.items():
          assert isinstance(
              v, tensor.Tensor
          ), "Only tensor state is allowed"
          tensor_dict[k] = tensor.to_numpy(v)
          states_attr[k] = {
              "state_type": self.MODEL_STATE_TYPE,
              "shape": v.shape,
              "dtype": v.dtype,
          }
  
      for k, v in aux_states.items():
          assert isinstance(
              v, tensor.Tensor
          ), "Only tensor aux state is allowed"
          tensor_dict[k] = tensor.to_numpy(v)
          states_attr[k] = {
              "state_type": self.AUX_STATE_TYPE,
              "shape": v.shape,
              "dtype": v.dtype,
          }
  
      # save to files
      timestamp = time.time()
      tmp_dir = "/tmp/singa_save_states_%s" % timestamp
      os.mkdir(tmp_dir)
      tensor_dict_fp = tmp_dir + self.TENSOR_DICT_FILENAME
      states_attr_fp = tmp_dir + self.STATES_ATTR_FILENAME
  
      np.savez(tensor_dict_fp, **tensor_dict)
  
      with open(states_attr_fp, "w") as fp:
          json.dump(states_attr, fp)
  
      compression = zipfile.ZIP_DEFLATED
      with zipfile.ZipFile(fpath, mode="w") as zf:
          zf.write(
              tensor_dict_fp,
              os.path.basename(tensor_dict_fp),
              compress_type=compression,
          )
          zf.write(
              states_attr_fp,
              os.path.basename(states_attr_fp),
              compress_type=compression,
          )
  
      # clean up tmp files
      os.remove(tensor_dict_fp)
      os.remove(states_attr_fp)
      os.rmdir(tmp_dir)
  
imports: import os
  import gc
  import time
  import json
  import zipfile
  import numpy
  from functools import wraps
  from collections import Iterable
  from singa import tensor
  from singa import autograd
  from singa import layer
  from .tensor import Tensor
  from .None import singa_wrap
label_desc: Use image node_id 10 for calling the Model obj's underlying member method code with example usage: obj.save_states(fpath, aux_states) without return types