MCPcopy Index your code
hub / github.com/apache/tvm / append_or_update

Method append_or_update

python/tvm/contrib/tvmjs.py:102–149  ·  view source on GitHub ↗

Commit a record to the manager. Parameters ---------- data: bytes Raw bytes to be appended. name: str The name of the parameter shape: tuple The shape of the array dtype: str The dtype information

(self, data, name, shape, dtype, encode_format, allow_update: bool = False)

Source from the content-addressed store, hash-verified

100 self.name_to_record[rec["name"]] = (idx, rec)
101
102 def append_or_update(self, data, name, shape, dtype, encode_format, allow_update: bool = False):
103 """Commit a record to the manager.
104
105 Parameters
106 ----------
107 data: bytes
108 Raw bytes to be appended.
109
110 name: str
111 The name of the parameter
112
113 shape: tuple
114 The shape of the array
115
116 dtype: str
117 The dtype information
118
119 encode_format:
120 The encode format of the entry
121
122 allow_update: bool
123 If the record already exists, update the record. Otherwise, raise an error.
124 """
125 rec = {
126 "name": name,
127 "shape": shape,
128 "dtype": dtype,
129 "format": encode_format,
130 "nbytes": len(data),
131 }
132 if name in self.name_to_record:
133 if not allow_update:
134 raise ValueError(f"Duplicate name {name} found in the cache.")
135 self.update_single_record(rec, data)
136 return
137
138 self.name_to_record[name] = (self.counter, rec)
139
140 if self.pending_nbytes + len(data) >= self.shard_cap_nbytes:
141 if len(data) * 2 >= self.shard_cap_nbytes:
142 # out of band data
143 rec["byteOffset"] = 0
144 self._commit_internal(data, [rec])
145 return
146 self.commit()
147 rec["byteOffset"] = self.pending_nbytes
148 self.curr_records.append(rec)
149 self.curr_data += data
150
151 def update_single_record(self, rec, data):
152 """Update a single record in a shard file."""

Callers 1

dump_tensor_cacheFunction · 0.95

Calls 4

update_single_recordMethod · 0.95
_commit_internalMethod · 0.95
commitMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected