# Buggy code
def serialize(self, name, f):
    """

    :param name:
    :param f:
    :type f: file
    :return:
    """
    param = self.get(name)
    size = reduce(lambda a, b: a * b, param.shape)
    f.write(struct.pack("IIQ", 0, 4, size))
    param = param.astype(np.float32)
    f.write(param.tobytes())


# Traceback (AttributeError)
/paddle/build {develop} ctest -R test_v2_api -V
UpdateCTestConfiguration  from :/paddle/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/paddle/build/DartConfiguration.tcl
Test project /paddle/build
Constructing a list of tests
Done constructing a list of tests
Checking test dependency graph...
Checking test dependency graph end
test 67
Start 67: test_v2_api

67: Test command: /bin/bash "/paddle/python/paddle/v2/tests/run_tests.sh" "/usr/bin/python2.7"
67: Test timeout computed to be: 9.99988e+06
67: Processing /paddle/paddle/dist/py_paddle-0.10.0-py2-none-any.whl
67: Requirement already satisfied: protobuf==3.1 in /usr/local/lib/python2.7/dist-packages (from py-paddle==0.10.0)
67: Requirement already satisfied: numpy>=1.8.0 in /usr/lib/python2.7/dist-packages (from py-paddle==0.10.0)
67: Requirement already satisfied: nltk>=3.2.2 in /usr/local/lib/python2.7/dist-packages (from py-paddle==0.10.0)
67: Requirement already satisfied: six>=1.9 in /usr/local/lib/python2.7/dist-packages (from protobuf==3.1->py-paddle==0.10.0)
67: Requirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.1->py-paddle==0.10.0)
67: Requirement already satisfied: appdirs>=1.4.0 in /usr/local/lib/python2.7/dist-packages (from setuptools->protobuf==3.1->py-paddle==0.10.0)
67: Requirement already satisfied: packaging>=16.8 in /usr/local/lib/python2.7/dist-packages (from setuptools->protobuf==3.1->py-paddle==0.10.0)
67: Requirement already satisfied: pyparsing in /usr/local/lib/python2.7/dist-packages (from packaging>=16.8->setuptools->protobuf==3.1->py-paddle==0.10.0)
67: Installing collected packages: py-paddle
67: Successfully installed py-paddle-0.10.0
67: test test_data_feeder.py
67: I0506 10:55:05.557036 24457 Util.cpp:166] commandline:  --use_gpu=0
67: .......
67: ----------------------------------------------------------------------
67: Ran 7 tests in 0.011s
67:
67: OK
67: .......
67: ----------------------------------------------------------------------
67: Ran 7 tests in 0.359s
67:
67: OK
67: test test_parameters.py
67: E
67: ======================================================================
67: ERROR: test_serialization (__main__.TestParameters)
67: ----------------------------------------------------------------------
67: Traceback (most recent call last):
67:   File "test_parameters.py", line 46, in test_serialization
67:     params.to_tar(tmp_file)
67:   File "/paddle/python/paddle/v2/parameters.py", line 270, in to_tar
67:     self.serialize(nm, buf)
67:   File "/paddle/python/paddle/v2/parameters.py", line 252, in serialize
67:     f.write(param.tobytes())
67: AttributeError: 'numpy.ndarray' object has no attribute 'tobytes'
67:
67: ----------------------------------------------------------------------
67: Ran 1 test in 0.007s
67:
67: FAILED (errors=1)
1/1 Test #67: test_v2_api ......................***Failed    2.17 sec

0% tests passed, 1 tests failed out of 1

# Fixed code
def serialize(self, name, f):
    """

    :param name:
    :param f:
    :type f: file
    :return:
    """
    param = self.get(name)
    size = reduce(lambda a, b: a * b, param.shape)
    f.write(struct.pack("IIQ", 0, 4, size))
    param = param.astype(np.float32)
    f.write(param.tostring())