MCPcopy Create free account
hub / github.com/pytorch/pytorch / renderBody

Method renderBody

torch/utils/model_dump/code.js:228–297  ·  view source on GitHub ↗
(indent, data)

Source from the content-addressed store, hash-verified

226 }
227
228 renderBody(indent, data) {
229 if (data === null || this.INLINE_TYPES.has(typeof(data))) {
230 throw "Should not reach here."
231 }
232 if (typeof(data) != "object") {
233 throw new Error("Not an object");
234 }
235 if (Array.isArray(data)) {
236 let new_indent = indent + "\u00A0\u00A0";
237 let parts = [];
238 for (let idx = 0; idx < data.length; idx++) {
239 // Does it make sense to put explicit index numbers here?
240 parts.push(html`<br/><${StructuredData} prefix=${idx + ": "} indent=${new_indent} data=${data[idx]} />`);
241 }
242 return parts;
243 }
244 if (data.__tuple_values__) {
245 // Handled the same as lists.
246 return this.renderBody(indent, data.__tuple_values__);
247 }
248 if (data.__is_dict__) {
249 let new_indent = indent + "\u00A0\u00A0";
250 let parts = [];
251 for (let idx = 0; idx < data.keys.length; idx++) {
252 if (typeof(data.keys[idx]) != "string") {
253 parts.push(html`<br/>${new_indent}Non-string key`);
254 } else {
255 parts.push(html`<br/><${StructuredData} prefix=${data.keys[idx] + ": "} indent=${new_indent} data=${data.values[idx]} />`);
256 }
257 }
258 return parts;
259 }
260 if (data.__module_type__) {
261 const mstate = data.state;
262 if (mstate === null || typeof(mstate) != "object") {
263 throw new Error("Bad module state");
264 }
265 let new_indent = indent + "\u00A0\u00A0";
266 let parts = [];
267 if (mstate.__is_dict__) {
268 // TODO: Less copy/paste between this and normal dicts.
269 for (let idx = 0; idx < mstate.keys.length; idx++) {
270 if (typeof(mstate.keys[idx]) != "string") {
271 parts.push(html`<br/>${new_indent}Non-string key`);
272 } else if (this.IGNORED_STATE_KEYS.has(mstate.keys[idx])) {
273 // Do nothing.
274 } else {
275 parts.push(html`<br/><${StructuredData} prefix=${mstate.keys[idx] + ": "} indent=${new_indent} data=${mstate.values[idx]} />`);
276 }
277 }
278 } else if (mstate.__tuple_values__) {
279 parts.push(html`<br/><${StructuredData} prefix="" indent=${new_indent} data=${mstate} />`);
280 } else if (mstate.__module_type__) {
281 // We normally wouldn't have the state of a module be another module,
282 // but we use "modules" to encode special values (like Unicode decode
283 // errors) that might be valid states. Just go with it.
284 parts.push(html`<br/><${StructuredData} prefix="" indent=${new_indent} data=${mstate} />`);
285 } else {

Callers 1

renderMethod · 0.95

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected