Spaces:
Sleeping
Sleeping
Commit ·
7f31eab
1
Parent(s): 9de43a5
print log about runtime cocurrency
Browse files14 unmodified lines15161718192021222347 unmodified lines717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311426 unmodified lines14114214314414514614714 unmodified lines
import osimport jsonimport logging
LOG = logging.getLogger('lilyscript')
import numpy as npimport onnxruntime as ort47 unmodified lines return e / e.sum()
def _physical_cores (): '''Best-effort physical (not logical/HT) core count via /proc/cpuinfo; None if unavailable. ORT's intra_op default (=0) maps to this on most CPU builds.''' try: phys, cur = set(), {} for line in open('/proc/cpuinfo'): line = line.strip() if not line: if 'physical id' in cur and 'core id' in cur: phys.add((cur['physical id'], cur['core id'])) cur = {} continue if ':' in line: k, v = line.split(':', 1) cur[k.strip()] = v.strip() return len(phys) or None except Exception: return None
def _log_thread_info (so, sess): '''Log host CPU capacity + the ONNX Runtime intra/inter-op thread settings that are actually in effect. intra_op_num_threads/inter_op_num_threads == 0 means "ORT auto" — it picks the number of physical cores for the intra-op pool.''' logical = os.cpu_count() affinity = len(os.sched_getaffinity(0)) if hasattr(os, 'sched_getaffinity') else logical physical = _physical_cores() intra = so.intra_op_num_threads inter = so.inter_op_num_threads effective_intra = intra if intra else (physical or affinity or logical) LOG.info('CPU: %s logical / %s physical cores, %s available (affinity)', logical, physical if physical is not None else '?', affinity) LOG.info('ONNX Runtime threads: intra_op=%s (%s), inter_op=%s (%s) | execution_mode=%s', intra, 'auto -> ~%s' % effective_intra if intra == 0 else 'explicit', inter, 'auto' if inter == 0 else 'explicit', getattr(so, 'execution_mode', '?'))
class StreamingLilyletGenerator: '''Loads the int8 KV ONNX sessions + vendored assets and streams generation.'''
26 unmodified lines os.path.join(model_dir, 'token_kv_int8.onnx'), so, providers=['CPUExecutionProvider']) self.patch_out_names = [o.name for o in self.patch_kv_sess.get_outputs()] self.token_out_names = [o.name for o in self.token_kv_sess.get_outputs()] _log_thread_info(so, self.patch_kv_sess)
# ---- text helpers (mirror LilyletPatchyGenerator.patch_to_text) ----
lilyscript/generator.py+42