fix(experts): split bank copies at page-locked boundaries; Original bench without the subcommand
With part of a file-mapped bank page-locked (`pin_resident`), an H2D copy that starts in registered pages and runs into unregistered ones is refused by the driver (CUDA_ERROR_INVALID_VALUE, first seen on the laptop run). `MappedExpertBank::copy_pieces` cuts a `cache_source` slice at every registered boundary and the four copy sites (prompt copy ring, cache fill, swap fill, PCIe staging) issue one copy per piece; one piece when nothing is locked, so the default path is unchanged. original_bench.sh: the `strata` binary takes the generate options directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1ef80a1fb0
commit
c9845eed52
@@ -314,6 +314,26 @@ impl<'ctx> MappedExpertBank<'ctx> {
|
||||
a >= lo && b < hi
|
||||
})
|
||||
}
|
||||
/// `bytes` (a `cache_source` slice) cut at every boundary of a `pin_resident` range, as (offset, length)
|
||||
/// pieces: one H2D copy must not start in registered pages and run into unregistered ones (the driver
|
||||
/// refuses it with CUDA_ERROR_INVALID_VALUE), so copy sites issue one copy per piece. One piece when nothing
|
||||
/// is page-locked.
|
||||
pub(crate) fn copy_pieces(&self, bytes: &[u8]) -> Vec<(usize, usize)> {
|
||||
let resident = self.resident.borrow();
|
||||
let start = bytes.as_ptr() as usize;
|
||||
let end = start + bytes.len();
|
||||
let mut cuts = vec![start, end];
|
||||
for &(a, n) in resident.iter() {
|
||||
for c in [a, a + n] {
|
||||
if c > start && c < end {
|
||||
cuts.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
cuts.sort_unstable();
|
||||
cuts.dedup();
|
||||
cuts.windows(2).map(|w| (w[0] - start, w[1] - w[0])).collect()
|
||||
}
|
||||
/// Bytes page-locked by `pin_resident`.
|
||||
pub fn resident_bytes(&self) -> u64 {
|
||||
self.resident.borrow().iter().map(|&(_, n)| n as u64).sum()
|
||||
|
||||
@@ -474,7 +474,14 @@ impl<'read, 'ctx> Ring<'read, 'ctx> {
|
||||
// Physical role-major bank layout requires three H2Ds. Same source
|
||||
// bytes and literal blob G/U/D layout; no decode/conversion/copy tmp.
|
||||
for (destination, source) in destinations.into_iter().zip(sources) {
|
||||
api.copy_registered(destination, source, stream)?;
|
||||
// one copy per registered/unregistered piece (`MappedExpertBank::copy_pieces`)
|
||||
for (offset, bytes) in bank.copy_pieces(source) {
|
||||
api.copy_registered(
|
||||
destination.checked_subspan(source.len(), offset, bytes)?,
|
||||
&source[offset..offset + bytes],
|
||||
stream,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -313,8 +313,10 @@ impl<'ctx> OriginalExpertCache<'ctx> {
|
||||
let mut offset = 0usize;
|
||||
for span in spans {
|
||||
let source = bank.cache_source(span)?;
|
||||
let destination = handle.checked_subspan(capacity, offset, source.len())?;
|
||||
api.copy(destination.qwen_address(), source, stream)?;
|
||||
for (at, bytes) in bank.copy_pieces(source) {
|
||||
let destination = handle.checked_subspan(capacity, offset + at, bytes)?;
|
||||
api.copy(destination.qwen_address(), &source[at..at + bytes], stream)?;
|
||||
}
|
||||
offset += source.len();
|
||||
}
|
||||
Ok(())
|
||||
@@ -523,13 +525,15 @@ impl<'ctx> OriginalExpertCache<'ctx> {
|
||||
let mut offset = 0usize;
|
||||
for span in spans {
|
||||
let source = bank.cache_source(span)?;
|
||||
let destination = handle.checked_subspan(capacity, offset, source.len())?;
|
||||
self.attempted = true;
|
||||
self.api.as_ref().ok_or(Error::ContextPoisoned)?.copy(
|
||||
destination.qwen_address(),
|
||||
source,
|
||||
api::Stream(0),
|
||||
)?;
|
||||
for (at, bytes) in bank.copy_pieces(source) {
|
||||
let destination = handle.checked_subspan(capacity, offset + at, bytes)?;
|
||||
self.attempted = true;
|
||||
self.api.as_ref().ok_or(Error::ContextPoisoned)?.copy(
|
||||
destination.qwen_address(),
|
||||
&source[at..at + bytes],
|
||||
api::Stream(0),
|
||||
)?;
|
||||
}
|
||||
offset += source.len();
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -244,7 +244,9 @@ impl<'ctx> schedule::OriginalVerifyCpuSink<'_, 'ctx> {
|
||||
let mut offset = staging + (q * stride) as u64;
|
||||
for part in s {
|
||||
let bytes = source.bank.cache_source(part)?;
|
||||
copy.enqueue_copy_h2d(offset, bytes)?;
|
||||
for (at, n) in source.bank.copy_pieces(bytes) {
|
||||
copy.enqueue_copy_h2d(offset + at as u64, &bytes[at..at + n])?;
|
||||
}
|
||||
offset += bytes.len() as u64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ MAX_NEW="${MAX_NEW:-128}"; REPEAT="${REPEAT:-2}"; MAX_CONTEXT="${MAX_CONTEXT:-81
|
||||
mkdir -p "$OUT"
|
||||
shard1="$MODEL_DIR/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf"
|
||||
shard2="$MODEL_DIR/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf"
|
||||
args=(generate --serve --pack "$PACK" --native "$shard1" --ple-gguf "$shard2" --expert-profile "$PROFILE"
|
||||
args=(--serve --pack "$PACK" --native "$shard1" --ple-gguf "$shard2" --expert-profile "$PROFILE"
|
||||
--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp "$MTP" --max-context "$MAX_CONTEXT"
|
||||
--kv int8 --prompt-cache 0 "$@")
|
||||
echo "strata ${args[*]}" > "$OUT/$label.cmd"
|
||||
|
||||
Reference in New Issue
Block a user