Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Fioti authored and Joe Fioti committed Jan 2, 2024
1 parent 6d9f917 commit e67d3e6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/mistral/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type DeviceCompiler = CudaFp16Compiler;
type DeviceCompiler = CPUCompiler;

fn main() {
let prompt = "[INST]Please write a python implementation of merge sort.[/INST]\n";
let prompt = "[INST]Here is a python implementation of merge sort:[/INST]\n";
let tokens_to_generate = 300;

println!("Creating graph...");
Expand Down Expand Up @@ -121,7 +121,7 @@ fn main() {
print!(
"{}{}",
prompt.white().bold(),
decode(&tokenizer, &[output_id]).green()
decode(&tokenizer, &[output_id]).bright_green()
);
std::io::stdout().flush().unwrap();

Expand All @@ -148,7 +148,7 @@ fn main() {
let output_id = sample_index(&decode_logits.data());
decode_logits.drop();
input_ids.push(output_id);
print!("{}", decode(&tokenizer, &[output_id]).green());
print!("{}", decode(&tokenizer, &[output_id]).bright_green());
std::io::stdout().flush().unwrap();

// Swap caches
Expand Down
29 changes: 23 additions & 6 deletions src/compilers/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ pub struct RemapDownstream(pub Vec<NodeIndex>);

impl Compiler for RemapDownstream {
fn compile(&self, graph: &mut Graph) {
let set = self.0.iter().copied().collect::<HashSet<_>>();
// Loop through state dict tensors marked as no_delete
for mut node in self
.0
Expand All @@ -324,12 +325,7 @@ impl Compiler for RemapDownstream {
.next()
.unwrap()
.target();
if graph
.graph
.edges_directed(new_node, Direction::Incoming)
.count()
> 1
{
if !is_from_set(new_node, graph, &set) {
break;
}
// Remap node to new node
Expand All @@ -340,6 +336,27 @@ impl Compiler for RemapDownstream {
}
}

fn is_from_set(node: NodeIndex, graph: &Graph, set: &HashSet<NodeIndex>) -> bool {
// Reverse dfs upward
let mut stack = vec![node];
while let Some(node) = stack.pop() {
if !set.contains(&node) {
let mut new_nodes = graph
.graph
.edges_directed(node, Direction::Incoming)
.filter(|e| !e.weight().is_schedule())
.map(|e| e.source())
.collect_vec();
if new_nodes.is_empty() {
// Node isn't from set and doesn't have upstream nodes
return false;
}
stack.append(&mut new_nodes);
}
}
true
}

#[cfg(test)]
mod tests {
use crate::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions src/compilers/metal/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ impl<T: MetalFloat> Compiler for MetalGatherCompiler<T> {
move_outgoing_edge(sum_reduce, gather, &mut graph.graph);
graph.graph.remove_node(arange);
graph.graph.remove_node(ind_copy);
graph.id_remap.retain(|_, v| *v != ind_copy);
graph.graph.remove_node(mul);
graph.graph.remove_node(sum_reduce);
}
Expand Down

0 comments on commit e67d3e6

Please sign in to comment.