1# Copyright (c) Meta Platforms, Inc. and affiliates. 2# All rights reserved. 3# 4# This source code is licensed under the BSD-style license found in the 5# LICENSE file in the root directory of this source tree. 6 7from xml.etree import ElementTree as ET 8 9from executorch.exir.verification.interpreter import Interpreter 10 11 12def get_header(name): 13 h2 = ET.Element("h2") 14 span = ET.Element("span") 15 span.text = name 16 h2.append(span) 17 18 return h2 19 20 21def iterable_to_html(s): 22 res = ET.Element("span") 23 val_node = ET.SubElement(res, "p") 24 25 for e in s: 26 br = ET.SubElement(val_node, "br") 27 br.text = str(e) 28 return res 29 30 31def gen_html(program): 32 test = Interpreter(program) 33 prog_opset = set(test.get_operators_list()) 34 35 prog_vals = test.get_constant_tensors() 36 html = ET.Element("html") 37 38 head = ET.Element("head") 39 html.append(head) 40 41 title = ET.Element("title") 42 head.append(title) 43 title.text = "Model" 44 45 body = ET.Element("body") 46 html.append(body) 47 div = ET.Element( 48 "div", 49 attrib={ 50 "id": "main_content", 51 "style": "position: absolute; width: 99%; height: 100%; overflow: scroll;", 52 }, 53 ) 54 body.append(div) 55 56 # Header: Operator List 57 div.append(get_header("Operator List")) 58 59 # Burn in data 60 div.append(iterable_to_html(prog_opset)) 61 62 # Header: Constant Tensor List 63 div.append(get_header("Constant Tensor List")) 64 65 # Burn in data 66 div.append(iterable_to_html(prog_vals)) 67 68 return ET.tostring(html) 69