def _reset_docs_for_sample(
        cls, collection_name, sample_id, frame_numbers, keep=False
    ):
        """Resets the backing documents for all in-memory frames with the given
        frame numbers attached to the specified sample.

        When ``keep=True``, all frames whose frame numbers are **not** in
        ``frame_numbers`` are reset instead.
        """
        if collection_name not in cls._instances:
            return

        samples = cls._instances[collection_name]
        frames = samples.get(str(sample_id), {})

        if not frames:
            return

        if callable(frame_numbers):
            frame_numbers = frame_numbers()

        frame_numbers = set(frame_numbers)
        reset_fns = set()

        if keep:
            for frame_number, frame in frames.items():
                if frame_number not in frame_numbers:
                    reset_fns.add(frame_number)
                    frame._reset_backing_doc()
        else:
            for frame_number, frame in frames.items():
                if frame_number in frame_numbers:
                    reset_fns.add(frame_number)
                    frame._reset_backing_doc()

        for frame_number in reset_fns:
            frames.pop(frame_number)
Resets the backing documents for all in-memory frames with the given
        frame numbers attached to the specified sample.

        When ``keep=True``, all frames whose frame numbers are **not** in
        ``frame_numbers`` are reset instead.
        
fiftyone/core/singletons.py