{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/optimizing-automatic-differentiation-with","title":"Optimizing Automatic Differentiation with Deep Reinforcement Learning","arxiv_id":"2406.05027","date":"2024-06-07","proceeding":null,"authors":["Jamie Lohoff","Emre Neftci"],"abstract":"Computing Jacobians with automatic differentiation is ubiquitous in many scientific domains such as machine learning, computational fluid dynamics, robotics and finance. Even small savings in the number of computations or memory usage in Jacobian computations can already incur massive savings in energy consumption and runtime. While there exist many methods that allow for such savings, they generally trade computational efficiency for approximations of the exact Jacobian. In this paper, we present a novel method to optimize the number of necessary multiplications for Jacobian computation by leveraging deep reinforcement learning (RL) and a concept called cross-country elimination while still computing the exact Jacobian. Cross-country elimination is a framework for automatic differentiation that phrases Jacobian accumulation as ordered elimination of all vertices on the computational graph where every elimination incurs a certain computational cost. We formulate the search for the optimal elimination order that minimizes the number of necessary multiplications as a single player game which is played by an RL agent. We demonstrate that this method achieves up to 33% improvements over state-of-the-art methods on several relevant tasks taken from diverse domains. Furthermore, we show that these theoretical gains translate into actual runtime improvements by providing a cross-country elimination interpreter in JAX that can efficiently execute the obtained elimination orders.","url_abs":"https://arxiv.org/abs/2406.05027v3","url_pdf":"https://arxiv.org/pdf/2406.05027v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[],"tasks":[{"task_slug":"computational-efficiency","task_name":"Computational Efficiency"},{"task_slug":"deep-reinforcement-learning","task_name":"Deep Reinforcement Learning"},{"task_slug":"reinforcement-learning","task_name":"Reinforcement Learning"},{"task_slug":"reinforcement-learning-1","task_name":"Reinforcement Learning (RL)"},{"task_slug":"reinforcement-learning-2","task_name":"reinforcement-learning"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2406.05027","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.05027"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/jamielohoff/graphax","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/jamielohoff/alphagrad","reach":null}],"summary":{"ran":11,"ran_fixture":1,"unverified":17},"by_repo_kind":{"found_in_text":{"samples":29,"ran":12,"repositories":2}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"1e3e284050f7aa84","entry":"add_elemental_rule","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/math.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/math.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1e3e284050f7aa84"}},{"code_sha256_prefix":"f493bdb09a28f07c","entry":"eye_like","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/sparse/utils.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/sparse/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f493bdb09a28f07c"}},{"code_sha256_prefix":"3643f85316c3c4ad","entry":"eye_like_copy","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/sparse/utils.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/sparse/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3643f85316c3c4ad"}},{"code_sha256_prefix":"9ced58452ae48749","entry":"get_aval_shape","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/base.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/base.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9ced58452ae48749"}},{"code_sha256_prefix":"0c5adab6e8148d63","entry":"get_ndim","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/base.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/base.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0c5adab6e8148d63"}},{"code_sha256_prefix":"27157b30c8cb1b83","entry":"get_shape","repo":"jamielohoff/alphagrad","repo_kind":"found_in_text","path":"src/alphagrad/vertexgame/core.py","file_url":"https://github.com/jamielohoff/alphagrad/blob/HEAD/src/alphagrad/vertexgame/core.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"27157b30c8cb1b83"}},{"code_sha256_prefix":"7cd542d5c5d2721c","entry":"get_shape","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/base.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/base.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7cd542d5c5d2721c"}},{"code_sha256_prefix":"13181dc7795c5de7","entry":"iota_elemental_only","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/structural.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/structural.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"13181dc7795c5de7"}},{"code_sha256_prefix":"c20b3a537fa9222a","entry":"sub_elemental_rule","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/math.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/math.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c20b3a537fa9222a"}},{"code_sha256_prefix":"3477609316330ba0","entry":"tree_allclose","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/utils.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3477609316330ba0"}},{"code_sha256_prefix":"e86d867de0350e04","entry":"with_type_promotion","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/math.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/math.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e86d867de0350e04"}},{"code_sha256_prefix":"7c57f2a75ae4fe9e","entry":"zeros_like","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/sparse/utils.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/sparse/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7c57f2a75ae4fe9e"}},{"code_sha256_prefix":"ff09a535363f2b4c","entry":"cross_country","repo":"jamielohoff/alphagrad","repo_kind":"found_in_text","path":"src/alphagrad/vertexgame/core.py","file_url":"https://github.com/jamielohoff/alphagrad/blob/HEAD/src/alphagrad/vertexgame/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ff09a535363f2b4c"}},{"code_sha256_prefix":"d0e6738929346739","entry":"device_put_elemental_rule","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/structural.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/structural.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d0e6738929346739"}},{"code_sha256_prefix":"58031c16445a9519","entry":"dot_general_elemental_only","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/linalg.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/linalg.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"58031c16445a9519"}},{"code_sha256_prefix":"f909c31e94402c11","entry":"dot_general_elemental_rule","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/linalg.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/linalg.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f909c31e94402c11"}},{"code_sha256_prefix":"61c62ae5257fa109","entry":"get_fmas_jacprod","repo":"jamielohoff/alphagrad","repo_kind":"found_in_text","path":"src/alphagrad/vertexgame/core.py","file_url":"https://github.com/jamielohoff/alphagrad/blob/HEAD/src/alphagrad/vertexgame/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"61c62ae5257fa109"}},{"code_sha256_prefix":"78d7b183cd04201e","entry":"iota_elemental_rule","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/structural.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/structural.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"78d7b183cd04201e"}},{"code_sha256_prefix":"c6f1447ed053ebb2","entry":"jacve","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/core.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c6f1447ed053ebb2"}},{"code_sha256_prefix":"f55fecb3286bee3e","entry":"measure","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"performance_measurements/perf.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/performance_measurements/perf.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f55fecb3286bee3e"}},{"code_sha256_prefix":"2f45e8735e37c6fa","entry":"measure_execution_time_with_jax","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"performance_measurements/perf.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/performance_measurements/perf.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2f45e8735e37c6fa"}},{"code_sha256_prefix":"a33b526df34622a8","entry":"reduce_sum_elemental_rule","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/reductions.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/reductions.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a33b526df34622a8"}},{"code_sha256_prefix":"e087ddcd2fd02c8f","entry":"select_elemental_only","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/reductions.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/reductions.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e087ddcd2fd02c8f"}},{"code_sha256_prefix":"f12c8af8592424e6","entry":"select_elemental_rule","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/primitives/reductions.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/primitives/reductions.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f12c8af8592424e6"}},{"code_sha256_prefix":"f794181f1d75bbc9","entry":"sparsity_fmas_map","repo":"jamielohoff/alphagrad","repo_kind":"found_in_text","path":"src/alphagrad/vertexgame/core.py","file_url":"https://github.com/jamielohoff/alphagrad/blob/HEAD/src/alphagrad/vertexgame/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f794181f1d75bbc9"}},{"code_sha256_prefix":"7eb5241a707e9579","entry":"sparsity_where","repo":"jamielohoff/alphagrad","repo_kind":"found_in_text","path":"src/alphagrad/vertexgame/core.py","file_url":"https://github.com/jamielohoff/alphagrad/blob/HEAD/src/alphagrad/vertexgame/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7eb5241a707e9579"}},{"code_sha256_prefix":"45119ffdcd9245c8","entry":"unload_post_transforms","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/core.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"45119ffdcd9245c8"}},{"code_sha256_prefix":"76547d6365d31f62","entry":"unload_pre_transforms","repo":"jamielohoff/graphax","repo_kind":"found_in_text","path":"src/graphax/core.py","file_url":"https://github.com/jamielohoff/graphax/blob/HEAD/src/graphax/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"76547d6365d31f62"}},{"code_sha256_prefix":"c1b89909991b710c","entry":"vertex_eliminate","repo":"jamielohoff/alphagrad","repo_kind":"found_in_text","path":"src/alphagrad/vertexgame/core.py","file_url":"https://github.com/jamielohoff/alphagrad/blob/HEAD/src/alphagrad/vertexgame/core.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c1b89909991b710c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}