Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.
A .serva file is bytes on disk like any other file. Unpacking means loading those bytes into something you can compute on, so a training job or an analysis can read the file as it stands.Dependencies: none for reading the bytes, numpy and torch for the sections that use them.
Open one file
Path.read_bytes returns the whole file as a bytes object. There is no reader to install and no password to supply, because nothing is being decoded at this point.
from pathlib import Pathraw = Path("sample.serva").read_bytes()print(len(raw), "bytes")print(raw[:16].hex()) # the first 16 bytes, as hex
Into a NumPy array
Bytes map straight onto uint8, one value per byte, in the range 0 to 255.
The bytearray is worth keeping. read_bytes hands back an immutable bytes object, and PyTorch has no read only tensor, so passing one straight in warns that the tensor can write into a buffer that is meant to be immutable. Wrapping it gives PyTorch a buffer it is allowed to own and the warning goes away. Cast to float() when your model wants floats.
The blocks inside
Everything above treats the file as one flat run of bytes. get_blocks reads its structure instead it slices the container on disk and returns each block’s hypervector as uint8. No request, no key, and nothing is decoded.
from serva import get_blocks, get_blockblocks = get_blocks("talk.serva")print(len(blocks), "blocks") # 26 blocksprint(blocks[0].shape, blocks[0].dtype) # (9802,) uint8print(get_block("talk.serva", 0).shape) # (9802,) the same block
A folder of files
One file is easy. A dataset is where the real work is, because every .serva file has a different length and nothing stacks into a batch until they all match.Start by looking at the spread:
from pathlib import Pathimport numpy as npfiles = sorted(Path("data/train").rglob("*.serva"))sizes = np.array([p.stat().st_size for p in files])print(f"{len(files)} files")print(f"smallest {sizes.min():,} largest {sizes.max():,} median {int(np.median(sizes)):,}")
The simplest thing that works is to pad every file to the largest one:
width = int(sizes.max())X = np.zeros((len(files), width), dtype=np.uint8)for i, p in enumerate(files): raw = p.read_bytes() X[i, : len(raw)] = np.frombuffer(raw, dtype=np.uint8)print(X.shape) # (n_files, width)
That is fine when your files are roughly the same size. When they are not, it is wasteful: a set whose largest file is ten times the median spends most of its memory on zeros. Two ways out:
Pick a fixed width and pad or truncate to it. Cheap and predictable, but anything past the cut is thrown away, so choose it from the size spread rather than by guessing.
Pad per batch instead of per dataset, to the longest file in that batch only, and carry a mask marking which positions are real. Keeps every byte and adds the least padding possible.
Whichever you choose, keep the padding value at zero and stay consistent across train and validation. A model that learns where the padding starts is learning file size, not content.
Or let the SDK do it
ServaDataset in the Python SDK does everything above for you: it walks the folder, reads each file, handles the length problem, and hands your loader a tensor.
from serva.torch import ServaDatasetfrom torch.utils.data import DataLoaderds = ServaDataset("data/train")loader = DataLoader(ds, batch_size=32, shuffle=True)for batch in loader: ... # your model, your training step
Class subfolders become labels, a flat folder gives you bare tensors, and length=None with pad_collate is the per batch padding described above. The PyTorch page covers the options in full.
Visualize .serva files projects a folder of them to see how they sit relative to each other.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Servamind · Serva Encoder","description":"Servamind documentation for Serva Encoder — `.serva` files, compression API, and AES-256-GCM encryption.","colors":{"primary":"#2d6cdf","light":"#2d6cdf","dark":"#2d6cdf"},"logo":{"light":"https://mintcdn.com/servamind/ZepuPg9fqB7I8LaW/assets/Serva-Encoder-Color.png?fit=max\u0026auto=format\u0026n=ZepuPg9fqB7I8LaW\u0026q=85\u0026s=7fd3dec0f43e0f613d29e65c8dccddb1","dark":"https://mintcdn.com/servamind/ZepuPg9fqB7I8LaW/assets/Serva-Encoder-Light.png?fit=max\u0026auto=format\u0026n=ZepuPg9fqB7I8LaW\u0026q=85\u0026s=cf42dd646b0b9f3057fdca172a6c022a"},"favicon":"https://mintcdn.com/servamind/ZepuPg9fqB7I8LaW/assets/servamind-logo.png?fit=max\u0026auto=format\u0026n=ZepuPg9fqB7I8LaW\u0026q=85\u0026s=79f0ed57b94a2b374b9e0d3119545e3a","styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"servamind","hasAudioNarration":false,"actualSubdomain":"servamind","customDomains":[],"gitSource":{"type":"github","owner":"servamind","repo":"serva_webapp_docs","deployBranch":"main","contentDirectory":"docs","isPrivate":true,"mountPath":"","label":""},"entitlements":{},"buildId":"6aac6029ea621e00184a5d78","clientVersion":"0.0.4340","searchFilterCounts":[{"language":"default","tag":"API reference","count":5},{"language":"default","tag":"Tutorials","count":5},{"language":"default","tag":"API keys","count":3},{"language":"default","tag":"Client SDK","count":3},{"language":"default","tag":"Usage","count":1},{"language":"default","tag":"Logging / metrics","count":1},{"language":"default","tag":"Preparing data","count":1},{"language":"default","tag":"Training","count":1},{"language":"default","tag":"Unpacking","count":1},{"language":"default","tag":"Visualization","count":1}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"#header:has(+#content[data-page-href$=\"/guides/basics\"]){display:none}#sidebar::after{content:\"\";position:absolute;left:0;right:2rem;bottom:1.2rem;z-index:15;height:2.75rem;pointer-events:none;background-image:url(\"/assets/Servamind-Color.png\");background-repeat:no-repeat;background-position:calc(50% - 0.5rem) bottom;background-size:65% auto;box-sizing:border-box}html.dark #sidebar::after{background-image:url(\"/assets/Servamind-Light.png\")}#sidebar-content{padding-bottom:4rem!important}"}]}
{"page":{"pagePath":"tutorials/unpacking/unpack-serva-files","slug":"/tutorials/unpacking/unpack-serva-files","pageMetadata":{"title":"Unpack a `.serva` file","description":"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.","href":"/tutorials/unpacking/unpack-serva-files"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,hr:`hr`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Tip}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Tip)_missingMdxReference(`Tip`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`A `,_jsx(_components.code,{children:`.serva`}),` file is bytes on disk like any other file. `,_jsx(_components.strong,{children:`Unpacking`}),` means loading those bytes into something you can compute on, so a training job or an analysis can read the file as it stands.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Dependencies:`}),` none for reading the bytes, `,_jsx(_components.code,{children:`numpy`}),` and `,_jsx(_components.code,{children:`torch`}),` for the sections that use them.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`open-one-file`,children:`Open one file`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`Path.read_bytes`}),` returns the whole file as a `,_jsx(_components.code,{children:`bytes`}),` object. There is no reader to install and no password to supply, because nothing is being decoded at this point.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pathlib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`raw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"sample.serva\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).read_bytes()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(raw), `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"bytes\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(raw[:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`16`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].hex()) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# the first 16 bytes, as hex`})]}),`\n`]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`into-a-numpy-array`,children:`Into a NumPy array`}),`\n`,_jsxs(_components.p,{children:[`Bytes map straight onto `,_jsx(_components.code,{children:`uint8`}),`, one value per byte, in the range 0 to 255.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` numpy `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pathlib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`raw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"sample.serva\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).read_bytes()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`x `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np.frombuffer(raw, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`dtype`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`np.uint8)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(x.shape, x.dtype) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# (41231,) uint8`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`np.frombuffer`}),` does not copy, so the array is a view over the bytes you read. Call `,_jsx(_components.code,{children:`.copy()`}),` if you plan to write to it.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`into-a-pytorch-tensor`,children:`Into a PyTorch tensor`}),`\n`,_jsx(_components.p,{children:`Same idea, with one wrinkle worth knowing.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` torch`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pathlib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`raw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"sample.serva\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).read_bytes()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`x `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` torch.frombuffer(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`bytearray`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(raw), `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`dtype`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`torch.uint8)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(x.shape, x.dtype) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# torch.Size([41231]) torch.uint8`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`bytearray`}),` is worth keeping. `,_jsx(_components.code,{children:`read_bytes`}),` hands back an immutable `,_jsx(_components.code,{children:`bytes`}),` object, and PyTorch has no read only tensor, so passing one straight in warns that the tensor can write into a buffer that is meant to be immutable. Wrapping it gives PyTorch a buffer it is allowed to own and the warning goes away. Cast to `,_jsx(_components.code,{children:`float()`}),` when your model wants floats.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`the-blocks-inside`,children:`The blocks inside`}),`\n`,_jsxs(_components.p,{children:[`Everything above treats the file as one flat run of bytes. `,_jsx(_components.code,{children:`get_blocks`}),` reads its structure instead it slices the container on disk and returns each block’s hypervector as `,_jsx(_components.code,{children:`uint8`}),`. No request, no key, and nothing is decoded.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` serva `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` get_blocks, get_block`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`blocks `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` get_blocks(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"talk.serva\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(blocks), `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"blocks\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# 26 blocks`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(blocks[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].shape, blocks[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].dtype) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# (9802,) uint8`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(get_block(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"talk.serva\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).shape) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# (9802,) the same block`})]}),`\n`]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`a-folder-of-files`,children:`A folder of files`}),`\n`,_jsxs(_components.p,{children:[`One file is easy. A dataset is where the real work is, because `,_jsxs(_components.strong,{children:[`every `,_jsx(_components.code,{children:`.serva`}),` file has a different length`]}),` and nothing stacks into a batch until they all match.`]}),`\n`,_jsx(_components.p,{children:`Start by looking at the spread:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pathlib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` numpy `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`files `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` sorted`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(Path(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"data/train\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).rglob(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"*.serva\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`sizes `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np.array([p.stat().st_size `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` p `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` files])`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(files)`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` files\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"smallest `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`sizes.min()`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`:,}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` largest `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`sizes.max()`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`:,}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` median `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(np.median(sizes))`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`:,}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`The simplest thing that works is to pad every file to the largest one:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`width `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(sizes.max())`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`X `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np.zeros((`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(files), width), `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`dtype`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`np.uint8)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` i, p `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` enumerate`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(files):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` raw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` p.read_bytes()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` X[i, : `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(raw)] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np.frombuffer(raw, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`dtype`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`np.uint8)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(X.shape) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# (n_files, width)`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`That is fine when your files are roughly the same size. When they are not, it is wasteful: a set whose largest file is ten times the median spends most of its memory on zeros. Two ways out:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Pick a fixed width`}),` and pad or truncate to it. Cheap and predictable, but anything past the cut is thrown away, so choose it from the size spread rather than by guessing.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Pad per batch`}),` instead of per dataset, to the longest file in that batch only, and carry a mask marking which positions are real. Keeps every byte and adds the least padding possible.`]}),`\n`]}),`\n`,_jsx(Tip,{children:_jsx(_components.p,{children:`Whichever you choose, keep the padding value at zero and stay consistent across train and validation. A model that learns where the padding starts is learning file size, not content.`})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`or-let-the-sdk-do-it`,children:`Or let the SDK do it`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ServaDataset`}),` in the Python SDK does everything above for you: it walks the folder, reads each file, handles the length problem, and hands your loader a tensor.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` serva.torch `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ServaDataset`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` torch.utils.data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` DataLoader`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`ds `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ServaDataset(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"data/train\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`loader `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` DataLoader(ds, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`batch_size`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`32`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`shuffle`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` batch `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` loader:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` ...`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # your model, your training step`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Class subfolders become labels, a flat folder gives you bare tensors, and `,_jsx(_components.code,{children:`length=None`}),` with `,_jsx(_components.code,{children:`pad_collate`}),` is the per batch padding described above. The `,_jsx(_components.a,{href:`/sdk/pytorch`,children:`PyTorch page`}),` covers the options in full.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`where-to-go-next`,children:`Where to go next`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsxs(_components.a,{href:`/tutorials/training/serva-resnet-tutorial`,children:[`Train a classifier on `,_jsx(_components.code,{children:`.serva`}),` files`]}),` takes the loaded bytes through feature extraction and a full training run.`]}),`\n`,_jsxs(_components.li,{children:[_jsxs(_components.a,{href:`/tutorials/visualization/visualize-serva-files`,children:[`Visualize `,_jsx(_components.code,{children:`.serva`}),` files`]}),` projects a folder of them to see how they sit relative to each other.`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Unpack a `.serva` file","description":"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.","href":"/tutorials/unpacking/unpack-serva-files"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Open one file","slug":"open-one-file","depth":2,"children":[]},{"title":"Into a NumPy array","slug":"into-a-numpy-array","depth":2,"children":[]},{"title":"Into a PyTorch tensor","slug":"into-a-pytorch-tensor","depth":2,"children":[]},{"title":"The blocks inside","slug":"the-blocks-inside","depth":2,"children":[]},{"title":"A folder of files","slug":"a-folder-of-files","depth":2,"children":[]},{"title":"Or let the SDK do it","slug":"or-let-the-sdk-do-it","depth":2,"children":[]},{"title":"Where to go next","slug":"where-to-go-next","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"servamind","siteName":"Servamind · Serva Encoder","title":"Unpack a `.serva` file - Servamind · Serva Encoder","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-09-17T21:49:04.212Z","originalFileLocation":"tutorials/unpacking/unpack-serva-files.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Servamind · Serva Encoder\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Unpack a `.serva` file - Servamind · Serva Encoder\">\u003cmeta data-mint-head property=\"og:description\" content=\"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Servamind · Serva Encoder\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://servamind.mintlify.site/_mintlify/api/og/v2?division=Unpacking\u0026amp;title=Unpack+a+%60.serva%60+file\u0026amp;description=Load+.serva+bytes+into+a+buffer%2C+a+NumPy+array%2C+a+PyTorch+tensor%2C+or+read+the+blocks+inside%2C+with+no+decoding+and+no+password.\u0026amp;theme=ec3d04d21bec6cdd3f7b78a9\u0026amp;signature=a9f1dbebf670e29a1b07955eff8dd703fc654733ead6c57e94654162b1287071\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Unpack a `.serva` file - Servamind · Serva Encoder\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://servamind.mintlify.site/_mintlify/api/og/v2?division=Unpacking\u0026amp;title=Unpack+a+%60.serva%60+file\u0026amp;description=Load+.serva+bytes+into+a+buffer%2C+a+NumPy+array%2C+a+PyTorch+tensor%2C+or+read+the+blocks+inside%2C+with+no+decoding+and+no+password.\u0026amp;theme=ec3d04d21bec6cdd3f7b78a9\u0026amp;signature=a9f1dbebf670e29a1b07955eff8dd703fc654733ead6c57e94654162b1287071\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/servamind/qrX3Yonj8yz5-bDE/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Servamind · Serva Encoder\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#2d6cdf\">\u003clink data-mint-head rel=\"canonical\" href=\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/tutorials/unpacking/unpack-serva-files.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://servamind.mintlify.app/#organization\",\"name\":\"Servamind · Serva Encoder\",\"url\":\"https://servamind.mintlify.app\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/servamind/ZepuPg9fqB7I8LaW/assets/Serva-Encoder-Color.png?fit=max\u0026auto=format\u0026n=ZepuPg9fqB7I8LaW\u0026q=85\u0026s=7fd3dec0f43e0f613d29e65c8dccddb1\"}},{\"@type\":\"WebSite\",\"@id\":\"https://servamind.mintlify.app#website\",\"name\":\"Servamind · Serva Encoder\",\"url\":\"https://servamind.mintlify.app\",\"publisher\":{\"@id\":\"https://servamind.mintlify.app/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files#webpage\",\"url\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files\",\"name\":\"Unpack a `.serva` file\",\"description\":\"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.\",\"dateModified\":\"2026-09-17T21:49:04.212Z\",\"isPartOf\":{\"@id\":\"https://servamind.mintlify.app#website\"},\"breadcrumb\":{\"@id\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tutorials\",\"item\":\"https://servamind.mintlify.app/tutorials/preparing-data/split-columns\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unpack a `.serva` file\",\"item\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files#article\",\"headline\":\"Unpack a `.serva` file\",\"name\":\"Unpack a `.serva` file\",\"description\":\"Load .serva bytes into a buffer, a NumPy array, a PyTorch tensor, or read the blocks inside, with no decoding and no password.\",\"url\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files\",\"mainEntityOfPage\":{\"@id\":\"https://servamind.mintlify.app/tutorials/unpacking/unpack-serva-files#webpage\"},\"dateModified\":\"2026-09-17T21:49:04.212Z\",\"publisher\":{\"@id\":\"https://servamind.mintlify.app/#organization\"},\"isPartOf\":{\"@id\":\"https://servamind.mintlify.app#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Servamind · Serva Encoder\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Servamind · Serva Encoder\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/tutorials/unpacking/unpack-serva-files.md","siteName":"Servamind · Serva Encoder","nav":{"global":null,"pages":[{"title":"Basics","href":"/guides/basics"},{"group":"Tutorials","pages":[{"group":"Preparing data","pages":[{"title":"Split a file before encoding","description":"Group similar values together before encoding, so each piece compresses on its own and a training run loads only the parts it needs.","href":"/tutorials/preparing-data/split-columns"}]},{"group":"Unpacking","pages":[{"title":"Unpack a `.serva` file","href":"/tutorials/unpacking/unpack-serva-files"}]},{"group":"Training","pages":[{"title":"Train a classifier on .serva files","description":"Servamind · Serva Encoder — classify `.serva` file bytes with a Walsh-Hadamard transform and MLP: data-agnostic, non-spatial, plain PyTorch, no decoding.","href":"/tutorials/training/serva-resnet-tutorial"}]},{"group":"Visualization","pages":[{"title":"Visualize `.serva` files","href":"/tutorials/visualization/visualize-serva-files"}]},{"group":"Logging / metrics","pages":[{"title":"Check compression rate","href":"/tutorials/logging-metrics/compression-rate"}]}]},{"group":"API reference","pages":[{"title":"Introduction","tag":"Beta","href":"/reference/api-library"},{"group":"API keys","pages":[{"title":"Generate API key","openapi":"serva-webapp-openapi.yaml POST /keys","href":"/reference/api/keys-create"},{"title":"List API keys","openapi":"serva-webapp-openapi.yaml GET /keys","href":"/reference/api/keys-list"},{"title":"Revoke API key","openapi":"serva-webapp-openapi.yaml DELETE /keys/{key_id}","href":"/reference/api/keys-revoke"}]},{"group":"Usage","pages":[{"title":"Usage","openapi":"serva-webapp-openapi.yaml GET /api/usage","href":"/reference/api/usage"}]}]},{"group":"Client SDK","pages":[{"title":"Client SDK","tag":"Beta","href":"/sdk/overview"},{"title":"Hugging Face","href":"/sdk/huggingface"},{"title":"PyTorch","href":"/sdk/pytorch"}]}]},"basePath":"","title":"Unpack a `.serva` file - Servamind · Serva Encoder","deploymentId":"dpl_EtLmMeZHkKGqAjV1DiX4ZXCriDj3","buildId":"dpl_EtLmMeZHkKGqAjV1DiX4ZXCriDj3","dynamics":[],"chunks":[]}