{"record":{"id":"04953e1b4350b614","repo":"xai-org/x-algorithm","slug":"unsupported-emb-table-dtype-embeddings-dtype","errorCode":null,"errorMessage":"Unsupported emb_table dtype: {embeddings.dtype}","messagePattern":"Unsupported emb_table dtype: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/inference/h2d.py","lineNumber":412,"sourceCode":"    )\n    if embeddings.ndim != 2:\n        raise ValueError(f\"Expected 2D emb_table, got shape={embeddings.shape}\")\n    row_size = embeddings.shape[1]\n    scale = 1.0 / math.sqrt(row_size)\n    unique_rows = np.unique(row_indexes)\n    for row in unique_rows:\n        idx = int(row)\n        first = int(embeddings[idx, 0])\n        if first != 0:\n            continue\n        rng = np.random.default_rng(idx)\n        values = rng.uniform(-scale, scale, size=row_size).astype(np.float32)\n        if embeddings.dtype == np.uint16:\n            embeddings[idx] = (values.view(np.uint32) >> 16).astype(np.uint16)\n        elif embeddings.dtype == np.uint32:\n            embeddings[idx] = values.view(np.uint32)\n        else:\n            raise ValueError(f\"Unsupported emb_table dtype: {embeddings.dtype}\")\n","sourceCodeStart":394,"sourceCodeEnd":413,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/inference/h2d.py#L394-L413","documentation":"_maybe_init_rows lazily fills uninitialized embedding rows by generating random float32 values and bit-casting them into the table's storage dtype: uint16 stores the high 16 bits (bfloat16-style truncation via values.view(np.uint32) >> 16) and uint32 stores the full bits. Any other dtype has no defined bit-cast path, so it raises rather than writing garbage. Reached from lookup_h2d_embeddings.","triggerScenarios":"Calling lookup_h2d_embeddings with an emb_table whose dtype is float32, float16, int32, or anything other than np.uint16/np.uint32 while some row indexes are uninitialized. Note a table created via create_h2d_state will always be uint16/uint32, so this only happens with externally supplied tables.","commonSituations":"Passing a native float32 numpy table built for debugging instead of the uint view; reusing a dtype from a different pipeline; a checkpoint conversion step that emits float32 arrays directly.","solutions":["Re-create the table with the dtype from create_h2d_state ('bfloat16'->np.uint16, 'float32'->np.uint32)","Convert an existing table: table.astype(np.uint32) for float32 values or proper bfloat16 bit conversion for uint16","If a new storage dtype is genuinely needed, add an explicit branch in _maybe_init_rows with a correct bit-cast"],"exampleFix":"# before\ntable = np.zeros((vocab, dim), dtype=np.float32)\nrows = lookup_h2d_embeddings(idx, table, ...)  # lazy init -> error\n# after\ntable = np.zeros((vocab, dim), dtype=np.uint32)\nrows = lookup_h2d_embeddings(idx, table, ...)","handlingStrategy":"validation","validationCode":"import numpy as np\nassert table.dtype in (np.uint16, np.uint32), f\"bad table dtype {table.dtype}\"","typeGuard":"def is_supported_table_dtype(a: np.ndarray) -> bool:\n    return a.dtype in (np.dtype(np.uint16), np.dtype(np.uint32))","tryCatchPattern":null,"preventionTips":["Only pass tables produced by create_h2d_state or converted with the documented bit-cast","Unit-test dtype round-trips when adding new embedding precisions"],"tags":["dtype","embedding","numpy","bit-cast"],"backgroundTag":"unsupported-dtype","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}