1"""Generate a mock model for LLVM tests for Register Allocation.
2The generated model is not a neural net - it is just a tf.function with the
3correct input and output parameters.
11POLICY_DECISION_LABEL =
"priority"
12POLICY_OUTPUT_SPEC =
"""
15 "logging_name":
"priority",
17 "name":
"StatefulPartitionedCall",
27PER_LIVEINTERVAL_INT64_FEATURE_LIST = ["li_size", "stage"]
28PER_LIVEINTERVAL_FLOAT32_FEATURE_LIST = ["weight"]
29PER_LIVEINTERVAL_FEATURE_LIST = (
30 PER_LIVEINTERVAL_FLOAT32_FEATURE_LIST + PER_LIVEINTERVAL_INT64_FEATURE_LIST
32CONTEXT_FEATURE_LIST = ("discount",
"reward",
"step_type")
36 """Returns (time_step_spec, action_spec) for LLVM register allocation."""
38 (key, tf.TensorSpec(dtype=tf.int64, shape=(), name=key))
39 for key
in PER_LIVEINTERVAL_INT64_FEATURE_LIST
43 (key, tf.TensorSpec(dtype=tf.float32, shape=(), name=key))
44 for key
in PER_LIVEINTERVAL_FLOAT32_FEATURE_LIST
49 (key, tf.TensorSpec(dtype=tf.float32, shape=(), name=key))
50 for key
in [
"discount",
"reward"]
55 (key, tf.TensorSpec(dtype=tf.int32, shape=(), name=key))
56 for key
in [
"step_type"]
63 return os.path.join(path,
"output_spec.json")
67 """Build and save the mock model with the given signature."""
71 module.var = tf.Variable(0, dtype=tf.float32)
76 tf.cast(inputs[0][key], tf.float32)
77 for key
in PER_LIVEINTERVAL_FEATURE_LIST
82 [tf.cast(inputs[0][key], tf.float32)
for key
in CONTEXT_FEATURE_LIST]
86 result = s + module.var
87 return {POLICY_DECISION_LABEL: result}
89 module.action = tf.function()(action)
92 tf.saved_model.save(module, path, signatures=action)
94 with open(output_spec_path,
"w")
as f:
95 print(f
"Writing output spec to {output_spec_path}.")
96 f.write(POLICY_OUTPUT_SPEC)
100 assert len(argv) == 2
105if __name__ ==
"__main__":
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
def get_output_spec_path(path)
def get_input_signature()
def build_mock_model(path)