Use ast.literal_eval to parse checkpoint shape in colocated_python_benchmark#1367
Open
adityasingh2400 wants to merge 1 commit into
Open
Use ast.literal_eval to parse checkpoint shape in colocated_python_benchmark#1367adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
…nchmark create_state_spec_from_checkpoint read the shape field from the checkpoint index and ran it through eval() when it was a string. The shape is only ever a literal tuple or list of ints, so ast.literal_eval parses it identically while refusing to execute arbitrary code from an untrusted index file. This also lets the eval-used pylint suppression go away.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1364.
create_state_spec_from_checkpointincolocated_python_benchmark.pyreads the per-tensorshapefrom the checkpoint index returned byread_index_file, and when that value is a string it passes it toeval():The index file is loaded from the checkpoint path, which can come from an external or shared location, so this evaluates code from data that is not necessarily trusted.
The
shapeis only ever a literal tuple or list of integers, soast.literal_evalparses it to the same value while rejecting anything that is not a Python literal. This removes the code-execution path and lets the# pylint: disable=eval-usedsuppression go away.ast.literal_evalround-trips the shapes this code sees ("(2, 3)","(1024,)","[2, 3, 4]","()"), so behavior is unchanged for valid checkpoints.