diff --git a/.ci/docker/requirements.txt b/.ci/docker/requirements.txt index e6802cb045..dc01ea0c76 100644 --- a/.ci/docker/requirements.txt +++ b/.ci/docker/requirements.txt @@ -2,7 +2,7 @@ # Refer to ./jenkins/build.sh for tutorial build instructions sphinx==5.0.0 -sphinx-gallery==0.11.1 +sphinx-gallery==0.19.0 sphinx_design docutils==0.16 sphinx-copybutton diff --git a/.jenkins/validate_tutorials_built.py b/.jenkins/validate_tutorials_built.py index f5cd187dbc..5c9e60e90b 100644 --- a/.jenkins/validate_tutorials_built.py +++ b/.jenkins/validate_tutorials_built.py @@ -53,7 +53,6 @@ "intermediate_source/tensorboard_profiler_tutorial", # reenable after 2.0 release. "advanced_source/semi_structured_sparse", # reenable after 3303 is fixed. "intermediate_source/torchrec_intro_tutorial", # reenable after 3302 is fixe - "intermediate_source/memory_format_tutorial", # causes other tutorials like torch_logs fail. "state" issue, reseting dynamo didn't help ] def tutorial_source_dirs() -> List[Path]: diff --git a/conf.py b/conf.py index 05cfa11ca1..cd0c582e71 100644 --- a/conf.py +++ b/conf.py @@ -48,6 +48,35 @@ from pathlib import Path pio.renderers.default = 'sphinx_gallery' +import sphinx_gallery.gen_rst +import multiprocessing + +# Save the original function +def isolated_call(func, args, kwargs, result_queue): + try: + result = func(*args, **kwargs) + result_queue.put((True, result)) + except Exception as e: + result_queue.put((False, str(e))) + +def make_isolated_version(func): + def wrapper(*args, **kwargs): + result_queue = multiprocessing.Queue() + p = multiprocessing.Process( + target=isolated_call, + args=(func, args, kwargs, result_queue) + ) + p.start() + p.join() + success, result = result_queue.get() + if success: + return result + else: + raise RuntimeError(f"Error in isolated process: {result}") + return wrapper + +# Monkey-patch +sphinx_gallery.gen_rst.generate_file_rst = make_isolated_version(sphinx_gallery.gen_rst.generate_file_rst) try: import torchvision @@ -98,18 +127,7 @@ # -- Sphinx-gallery configuration -------------------------------------------- def reset_seeds(gallery_conf, fname): - torch.cuda.empty_cache() - torch.backends.cudnn.deterministic = True - torch.backends.cudnn.benchmark = False - torch._dynamo.reset() - torch._inductor.config.force_disable_caches = True - torch.manual_seed(42) - torch.set_default_device(None) - random.seed(10) - numpy.random.seed(10) - torch.set_grad_enabled(True) - - gc.collect() + pass sphinx_gallery_conf = { 'examples_dirs': ['beginner_source', 'intermediate_source', diff --git a/custom_directives.py b/custom_directives.py index 388aa262e6..3b22ec2d8c 100644 --- a/custom_directives.py +++ b/custom_directives.py @@ -88,7 +88,7 @@ def run(self): if 'intro' in self.options: intro = self.options['intro'][:195] + '...' else: - _, blocks = sphinx_gallery.gen_rst.split_code_and_text_blocks(abs_fname) + _, blocks = sphinx_gallery.py_source_parser.split_code_and_text_blocks(abs_fname) intro, _ = sphinx_gallery.gen_rst.extract_intro_and_title(abs_fname, blocks[0][1]) thumbnail_rst = ''