Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions eos/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ pub fn release_page_cache(file: &File) {
}
}

pub fn release_page_cache_range(file: &File, offset: u64, len: u64) {
if len == 0 {
return;
}
if let (Ok(offset), Ok(len)) = (libc::off_t::try_from(offset), libc::off_t::try_from(len)) {
unsafe {
libc::posix_fadvise(file.as_raw_fd(), offset, len, libc::POSIX_FADV_DONTNEED);
}
} else {
release_page_cache(file);
}
}

pub fn page_size() -> usize {
usize::try_from(unsafe { libc::sysconf(libc::_SC_PAGESIZE) }).unwrap_or(4096)
}
Expand Down
1 change: 1 addition & 0 deletions eos/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ fn reopen_direct(file: &File, sharing: u32) -> io::Result<File> {
}

pub fn release_page_cache(_: &File) {}
pub fn release_page_cache_range(_: &File, _: u64, _: u64) {}

pub fn page_size() -> usize {
let mut info: SYSTEM_INFO = unsafe { std::mem::zeroed() };
Expand Down
55 changes: 55 additions & 0 deletions flare-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,17 @@ impl ServingOptions {
if self.verify_weights {
options.push("--verify-weights".into());
}
if !self.hub.tensor_parallel.is_empty() {
options.extend([
"--tensor-parallel".into(),
self.hub
.tensor_parallel
.iter()
.map(u32::to_string)
.collect::<Vec<_>>()
.join(","),
]);
}
if let Some(n) = self.max_concurrency {
options.extend(["--max-concurrency".into(), n.to_string()]);
}
Expand Down Expand Up @@ -2584,4 +2595,48 @@ mod cache_cli_tests {
"--json and --plain must conflict"
);
}

#[test]
fn rank_options_forward_tensor_parallel() {
use clap::{CommandFactory, FromArgMatches};
let cli = Cli::try_parse_from([
"flare",
"run",
"model.safetensors",
"--tensor-parallel",
"2",
])
.unwrap();
let Command::Run(run) = cli.command else {
panic!("expected run");
};
assert_eq!(run.rank_options(), vec!["--tensor-parallel", "2"]);

let matches = Cli::command()
.try_get_matches_from([
"flare",
"orbit",
"run",
"model.safetensors",
"--tensor-parallel",
"4",
])
.unwrap();
let cli = Cli::from_arg_matches(&matches).unwrap();
let Command::Orbit(orbit) = cli.command else {
panic!("expected orbit");
};
let OrbitCommand::Run(run) = orbit.command else {
panic!("expected orbit run");
};
let run_matches = matches
.subcommand_matches("orbit")
.unwrap()
.subcommand_matches("run")
.unwrap();
assert_eq!(
run.rank_options(run_matches),
vec!["--tensor-parallel", "4"]
);
}
}
3 changes: 3 additions & 0 deletions flare-cli/src/core_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,12 @@ pub fn store_parallel<R: Read>(
let mut digest = Sha256::new();
std::io::copy(&mut &output, &mut digest)?;
if format!("{}.safetensors", hex(&digest.finalize())) != blob {
flare_helios::release_page_cache(&output);
return Err(format!("{name}: payload digest mismatch").into());
}
output.set_permissions(fs::Permissions::from_mode(0o444))?;
}
flare_helios::release_page_cache(&output);
Ok(())
})
}
Expand Down Expand Up @@ -555,6 +557,7 @@ fn store_partial(
}
fs::set_permissions(partial, fs::Permissions::from_mode(0o444))?;
}
flare_helios::release_page_cache(&output);
Ok(())
}

Expand Down
37 changes: 27 additions & 10 deletions flare-cli/src/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,18 @@ fn sha256_file(path: &Path) -> Result<[u8; 32], Failure> {
let mut file = File::open(path).map_err(|e| e.to_string())?;
let mut context = ring::digest::Context::new(&ring::digest::SHA256);
let mut buffer = vec![0u8; 4 << 20];
loop {
let read = file.read(&mut buffer).map_err(|e| e.to_string())?;
if read == 0 {
break;
let result = (|| -> Result<(), Failure> {
loop {
let read = file.read(&mut buffer).map_err(|e| e.to_string())?;
if read == 0 {
break;
}
context.update(&buffer[..read]);
}
context.update(&buffer[..read]);
}
Ok(())
})();
flare_helios::release_page_cache(&file);
result?;
Ok(context
.finish()
.as_ref()
Expand Down Expand Up @@ -1122,6 +1127,16 @@ impl Source {
for worker in workers {
worker.join().map_err(|_| "core source panicked")?;
}
// Peer shard files are not opened by rank zero's model loader, so release their
// Linux page cache here before CUDA initialization and KV cache sizing.
let mut seen = std::collections::HashSet::new();
for rank_files in &files {
for file in rank_files {
if seen.insert(Arc::as_ptr(file) as usize) {
flare_helios::release_page_cache(file);
}
}
}
for result in receiver.try_iter() {
if let Err(e) = result {
error.get_or_insert(e);
Expand Down Expand Up @@ -1197,10 +1212,12 @@ fn serve_source(
return Err("requested bytes are outside the rank's core ranges".into());
}
socket.write_all(&cache::range_bytes(&request.ranges).to_le_bytes())?;
io::copy(
&mut cache::RangeReader::new(&files[rank][request.file], &request.ranges),
&mut socket,
)?;
let file = &files[rank][request.file];
let copied = io::copy(&mut cache::RangeReader::new(file, &request.ranges), &mut socket);
for &(offset, size) in &request.ranges {
flare_helios::release_page_cache_range(file, offset, size);
}
copied?;
}
}

Expand Down
6 changes: 6 additions & 0 deletions flare-cli/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ impl Peers {
.to_owned(),
],
source: None,
envelope_digest: core.envelope_digest(),
tensor_parallel: core
.identity()
.ok()
.map(|id| id.tensor_parallel)
.filter(|&tp| tp > 0),
},
members,
rendezvous,
Expand Down
Loading
Loading