Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/opencl-windows-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
LLukas22 committed Jul 10, 2023
2 parents 7d673c2 + 7f13bb9 commit f85b377
Show file tree
Hide file tree
Showing 21 changed files with 534 additions and 189 deletions.
69 changes: 36 additions & 33 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,42 @@ jobs:
- name: Build
run: cargo build --verbose --features metal

# cuda:
# name: Build with cuda support
# strategy:
# # Don't stop building if it fails on an OS
# fail-fast: false
# matrix:
# os: [windows-latest, ubuntu-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: recursive
# - uses: Jimver/cuda-toolkit@v0.2.10
# if: matrix.os == 'ubuntu-latest'
# id: cuda-toolkit-linux
# with:
# cuda: '12.1.0'
# method: 'network'
# #See e.g. https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/
# sub-packages: '["nvcc","compiler","libraries","libraries-dev","cudart","cudart-dev","libcublas","libcublas-dev"]'
# - uses: Jimver/cuda-toolkit@v0.2.10
# if: matrix.os == 'windows-latest'
# id: cuda-toolkit-windows
# with:
# cuda: '12.1.0'
# method: 'network'
# #See https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html#install-the-cuda-software
# sub-packages: '["nvcc","cudart","visual_studio_integration","cublas_dev","cublas"]'
# - uses: dtolnay/rust-toolchain@stable
# - name: Check
# run: cargo check --verbose
# - name: Build
# run: cargo build --verbose --features cublas
cuda:
name: Build with cuda support
strategy:
# Don't stop building if it fails on an OS
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: Jimver/cuda-toolkit@v0.2.11
name: Install CUDA toolkit on Linux
if: matrix.os == 'ubuntu-latest'
id: cuda-toolkit-linux
with:
cuda: '12.2.0'
method: 'network'
#See e.g. https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/
non-cuda-sub-packages: '["libcublas","libcublas-dev"]'
sub-packages: '["nvcc","compiler","libraries","libraries-dev","cudart","cudart-dev"]'

- uses: Jimver/cuda-toolkit@v0.2.11
name: Install CUDA toolkit on Windows
if: matrix.os == 'windows-latest'
id: cuda-toolkit-windows
with:
cuda: '12.2.0'
#See https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html#install-the-cuda-software
method: 'local'
- uses: dtolnay/rust-toolchain@stable
- name: Check
run: cargo check --verbose
- name: Build
run: cargo build --verbose --features cublas

opencl:
name: Build with opencl support
Expand Down
11 changes: 10 additions & 1 deletion binaries/llm-test/configs/bloom.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"output_disabled": "When a llama rides a crab, ,.-\n\n/? ', , ; A;A = (b),d e orm\n“t” + “p。n unus et les el duetant alle that are by no ... ”\n( ? ) – ‘?\n!!\n«…..’,\nS.\n\n‘l」之 attergoir à dit-on pas .. 。。 ..\n– La leçon se confond quelquefois con ce qui es vée par occident .\n( 2 ) .\nLa protestation del paysan mécontent regardait pendre eussent mœurs faillite forteresse rivières lieues forteressemelés inquiétudes crackdown brawl slaughter massacresokea .\n» » … « …\n. . . \" \" ….",
"maximum_token_count": 128
}
},
{
"Tokens": {
"input": "Rustformers is",
"output": 15
}
},
{
"Delete": {}
}
]
}
}
11 changes: 10 additions & 1 deletion binaries/llm-test/configs/gptj.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"output_disabled": "\"When a llama rides a crab, \nit's not the same as when an elephant does it.\" - John Steinbeck, East of Eden.\n\n \"The best way to predict your future is by looking at history.\"- Robert Kiyosaki (author). Rich Dad Poor dad : what 10 rules for success really mean and how you can apply them in life! The rich dads guidebook on personal finance: How To Become A Millionaire In Less Than 5 years! http://www..richdadpoordaddyguidebooksalexanderkimballblogcom/the_bestwaytopredictyourfutureislookingathistory/. You will learn about money management",
"maximum_token_count": 128
}
},
{
"Tokens": {
"input": "Rustformers is",
"output": 257
}
},
{
"Delete": {}
}
]
}
}
11 changes: 10 additions & 1 deletion binaries/llm-test/configs/gptneox.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"output_disabled": "<|padding|>When a llama rides a crab, \n“The Greatest Show on Earth” is the title of an 1875 book by Phineas Taylor Barnum, who founded and operated The circus. He was born in Bethel Connecticut to Meshack (Meshake) Bowman Jr., from New York City; his mother’s name has not been recorded but she may have had some Native American ancestry as well.[2] His father died when he[3][4], at age three,[5]: 9–10 (p1), 11-12​—was left with relatives until they could find him work or send for them back home where there",
"maximum_token_count": 128
}
},
{
"Tokens": {
"input": "Rustformers is",
"output": 247
}
},
{
"Delete": {}
}
]
}
}
11 changes: 10 additions & 1 deletion binaries/llm-test/configs/llama.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"output": "When a llama rides a crab, 10-year olds are the ones who get to eat.\nTheir parents have been told that they will be eating for another year or two before their children can enjoy it again – and then only if there is enough food left over from Christmas dinner!",
"maximum_token_count": 128
}
},
{
"Tokens": {
"input": "Rustformers is",
"output": 260
}
},
{
"Delete": {}
}
]
}
}
11 changes: 10 additions & 1 deletion binaries/llm-test/configs/mpt.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"output": "When a llama rides a crab,  the llama is called the \"crab rider\".\nThe crabs are very popular in South America, especially Brazil. They have been used as transportation for many years and they can carry up to five people at once!",
"maximum_token_count": 128
}
},
{
"Tokens": {
"input": "Rustformers is",
"output": 247
}
},
{
"Delete": {}
}
]
}
}
30 changes: 30 additions & 0 deletions binaries/llm-test/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Tests that are run on every model, regardless of config.
pub(super) fn can_send<M: llm::KnownModel + 'static>(model: M) -> anyhow::Result<M> {
let model = std::thread::spawn(move || model)
.join()
.map_err(|e| anyhow::anyhow!("Failed to join thread: {e:?}"));

log::info!("`can_send` test passed!");

model
}

pub(super) fn can_roundtrip_hyperparameters<M: llm::KnownModel + 'static>(
model: &M,
) -> anyhow::Result<()> {
fn test_hyperparameters<M: llm::Hyperparameters>(hyperparameters: &M) -> anyhow::Result<()> {
let mut data = vec![];
hyperparameters.write_ggml(&mut data)?;
let new_hyperparameters =
<M as llm::Hyperparameters>::read_ggml(&mut std::io::Cursor::new(data))?;

assert_eq!(hyperparameters, &new_hyperparameters);

log::info!("`can_roundtrip_hyperparameters` test passed!");

Ok(())
}

test_hyperparameters(model.hyperparameters())
}
95 changes: 95 additions & 0 deletions binaries/llm-test/src/delete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//! Tests the model's token manipulation APIs:
//!
//! * [llm::InferenceSession::feed_prompt()]
//!
//! See [crate::TestCase::Tokens].
use std::convert::Infallible;

use llm::{InferenceFeedback, InferenceSession, Model, OutputRequest};
use serde::Serialize;

use crate::{TestCaseReport, TestCaseReportMeta};

/// Tests that models can delete tokens without changing the model's behavior.
pub(crate) fn can_delete(model: &impl Model) -> TestCaseReport {
let report = DeleteReport::default();
let mut session = model.start_session(Default::default());
let mut output = OutputRequest {
all_logits: Some(vec![]),
..Default::default()
};

// Feed some tokens
if let Err(err) = feed_prompt("The llama lived on the", &mut session, model, &mut output) {
return report.failure(&err.to_string());
}

// Add token and get the logits
if let Err(err) = feed_prompt(" ", &mut session, model, &mut output) {
return report.failure(&err.to_string());
}
let Some(original_logits) = output.all_logits.clone() else {
return report.failure("Model did not return logits.");
};

// Rewind, then re-add. Verify logits are the same.
if let Err(err) = session.rewind(model, 1) {
return report.failure(&err.to_string());
}
if let Err(err) = feed_prompt(" ", &mut session, model, &mut output) {
return report.failure(&err.to_string());
}
let Some(redone_logits) = output.all_logits.clone() else {
return report.failure("Second run of model did not return logits.");
};

// Compare the logits
for (idx, (&original, redone)) in original_logits.iter().zip(redone_logits).enumerate() {
if original > redone + f32::EPSILON || original < redone - f32::EPSILON {
return report.failure(&format!(
"Expected logits to be the same after delete, but differed at {idx}, \
expected {original}, but was {redone}."
));
}
}

log::info!("`can_delete` test passed!");
report.success()
}

fn feed_prompt(
prompt: &str,
session: &mut InferenceSession,
model: &impl Model,
output: &mut OutputRequest,
) -> Result<(), llm::InferenceError> {
session.feed_prompt(model, &Default::default(), prompt, output, always_continue)
}

fn always_continue(_: &[u8]) -> Result<InferenceFeedback, Infallible> {
Ok(InferenceFeedback::Continue)
}

#[derive(Serialize, Default)]
pub struct DeleteReport {
output: usize,
}

impl DeleteReport {
fn failure(self, msg: &str) -> TestCaseReport {
TestCaseReport {
meta: TestCaseReportMeta::Error {
error: msg.to_owned(),
},
report: crate::TestCaseReportInner::Delete(self),
}
}

fn success(self) -> TestCaseReport {
TestCaseReport {
meta: TestCaseReportMeta::Success,
report: crate::TestCaseReportInner::Delete(self),
}
}
}
Loading

0 comments on commit f85b377

Please sign in to comment.