# Buggy code
def make_tf_dataset(
    self, batch_size=100, epochs=1, deterministic=False, pad_batches=False
):
    """Create a tf.data.Dataset that iterates over the data in this Dataset.

    Each value returned by the Dataset's iterator is a tuple of (X, y,
    w) for one batch.

    Parameters
    ----------
    batch_size: int
      the number of samples to include in each batch
    epochs: int
      the number of times to iterate over the Dataset
    deterministic: bool
      if True, the data is produced in order.  If False, a different
      random permutation of the data is used for each epoch.
    pad_batches: bool
      if True, batches are padded as necessary to make the size of
      each batch exactly equal batch_size.

    Returns
    -------
    tf.Dataset that iterates over the same data.
    """
    # Retrieve the first sample so we can determine the dtypes.

    import tensorflow as tf

    X, y, w, ids = next(self.itersamples())
    dtypes = (tf.as_dtype(X.dtype), tf.as_dtype(y.dtype), tf.as_dtype(w.dtype))
    shapes = (
        tf.TensorShape([None] + list(X.shape)),
        tf.TensorShape([None] + list(y.shape)),
        tf.TensorShape([None] + list(w.shape)),
    )

    # Create a Tensorflow Dataset.

    def gen_data():
        for epoch in range(epochs):
            for X, y, w, ids in self.iterbatches(
                batch_size, epoch, deterministic, pad_batches
            ):
                yield (X, y, w)

    return tf.data.Dataset.from_generator(gen_data, dtypes, shapes)


# Traceback (AttributeError)
Traceback (most recent call last):
File "test_fit_on_batch.py", line 23, in <module>
model.fit_on_batch(X, y, w)
File "/Users/bharath/Code/deepchem/deepchem/models/keras_model.py", line 428, in fit_on_batch
if not self.built:
AttributeError: 'GraphConvModel' object has no attribute 'built'

# Fixed code
def make_tf_dataset(
    self, batch_size=100, epochs=1, deterministic=False, pad_batches=False
):
    """Create a tf.data.Dataset that iterates over the data in this Dataset.

    Each value returned by the Dataset's iterator is a tuple of (X, y,
    w) for one batch.

    Parameters
    ----------
    batch_size: int
      the number of samples to include in each batch
    epochs: int
      the number of times to iterate over the Dataset
    deterministic: bool
      if True, the data is produced in order.  If False, a different
      random permutation of the data is used for each epoch.
    pad_batches: bool
      if True, batches are padded as necessary to make the size of
      each batch exactly equal batch_size.

    Returns
    -------
    tf.Dataset that iterates over the same data.
    """
    # Retrieve the first sample so we can determine the dtypes.

    import tensorflow as tf

    X, y, w, ids = next(self.itersamples())
    dtypes = (tf.as_dtype(X.dtype), tf.as_dtype(y.dtype), tf.as_dtype(w.dtype))
    shapes = (
        tf.TensorShape([None] + list(X.shape)),
        tf.TensorShape([None] + list(y.shape)),
        tf.TensorShape([None] + list(w.shape)),
    )

    # Create a Tensorflow Dataset.

    def gen_data():
        for X, y, w, ids in self.iterbatches(
            batch_size, epochs, deterministic, pad_batches
        ):
            yield (X, y, w)

    return tf.data.Dataset.from_generator(gen_data, dtypes, shapes)