def _on_batch_overridden(callback):
    """Check if on_batch_begin or on_batch_end were overridden

    If the method does not exist at all, it's not considered overridden. This is
    mostly for callbacks that are mocked.

    """
    try:
        base_skorch_cls = next(cls for cls in callback.__class__.__mro__
                               if cls.__module__.startswith('skorch'))
    except StopIteration:
        # does not derive from skorch callback, possibly a mock
        return False

    obb = base_skorch_cls.on_batch_begin
    obe = base_skorch_cls.on_batch_end
    return (
        getattr(callback.__class__, 'on_batch_begin', obb) is not obb
        or getattr(callback.__class__, 'on_batch_end', obe) is not obe
    )