Unverified Commit bce74588 authored by Graham King's avatar Graham King Committed by GitHub
Browse files

chore: Rust to 1.89 and edition 2024 (#2659)

parent 268d017e
......@@ -13,7 +13,7 @@ use std::pin::Pin;
use futures::Stream;
use serde::Deserialize;
use crate::error::{map_deserialization_error, ApiError, OpenAIError};
use crate::error::{ApiError, OpenAIError, map_deserialization_error};
use super::{
MessageDeltaObject, MessageObject, RunObject, RunStepDeltaObject, RunStepObject, ThreadObject,
......
......@@ -8,7 +8,7 @@
// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
// Licensed under Apache 2.0
use base64::engine::{general_purpose, Engine};
use base64::engine::{Engine, general_purpose};
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
......
......@@ -24,7 +24,6 @@ use crate::{
use bytes::Bytes;
use super::{
responses::{CodeInterpreterContainer, Input, InputContent, Role as ResponsesRole},
AddUploadPartRequest, AudioInput, AudioResponseFormat, ChatCompletionFunctionCall,
ChatCompletionFunctions, ChatCompletionNamedToolChoice, ChatCompletionRequestAssistantMessage,
ChatCompletionRequestAssistantMessageContent, ChatCompletionRequestDeveloperMessage,
......@@ -40,6 +39,7 @@ use super::{
EmbeddingInput, FileInput, FilePurpose, FunctionName, Image, ImageInput, ImageModel,
ImageResponseFormat, ImageSize, ImageUrl, ImagesResponse, ModerationInput, Prompt, Role, Stop,
TimestampGranularity,
responses::{CodeInterpreterContainer, Input, InputContent, Role as ResponsesRole},
};
/// for `impl_from!(T, Enum)`, implements
......
......@@ -9,10 +9,10 @@
// Licensed under Apache 2.0
use crate::{
Client,
config::Config,
error::OpenAIError,
types::{AddUploadPartRequest, CompleteUploadRequest, CreateUploadRequest, Upload, UploadPart},
Client,
};
/// Allows you to upload large files in multiple parts.
......
......@@ -11,10 +11,10 @@
use serde::Serialize;
use crate::{
Client,
config::Config,
error::OpenAIError,
types::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest},
Client,
};
/// Manage users and their role in an organization. Users will be automatically added to the Default project.
......
......@@ -29,7 +29,7 @@ pub(crate) async fn file_stream_body(source: InputSource) -> Result<Body, OpenAI
_ => {
return Err(OpenAIError::FileReadError(
"Cannot create stream from non-file source".to_string(),
))
));
}
};
Ok(body)
......
......@@ -11,12 +11,12 @@
use serde::Serialize;
use crate::{
Client,
config::Config,
error::OpenAIError,
types::{
CreateVectorStoreFileBatchRequest, ListVectorStoreFilesResponse, VectorStoreFileBatchObject,
},
Client,
};
/// Vector store file batches represent operations to add multiple files to a vector store.
......
......@@ -11,13 +11,13 @@
use serde::Serialize;
use crate::{
Client,
config::Config,
error::OpenAIError,
types::{
CreateVectorStoreFileRequest, DeleteVectorStoreFileResponse, ListVectorStoreFilesResponse,
VectorStoreFileContentResponse, VectorStoreFileObject,
},
Client,
};
/// Vector store files represent files inside a vector store.
......
......@@ -11,6 +11,7 @@
use serde::Serialize;
use crate::{
Client, VectorStoreFiles,
config::Config,
error::OpenAIError,
types::{
......@@ -19,7 +20,6 @@ use crate::{
VectorStoreSearchResultsPage,
},
vector_store_file_batches::VectorStoreFileBatches,
Client, VectorStoreFiles,
};
pub struct VectorStores<'c, C: Config> {
......
......@@ -12,9 +12,9 @@
//! The purpose of this test to make sure that all _byot methods compiles with custom types.
use std::pin::Pin;
use dynamo_async_openai::{error::OpenAIError, Client};
use dynamo_async_openai::{Client, error::OpenAIError};
use futures::Stream;
use serde_json::{json, Value};
use serde_json::{Value, json};
impl dynamo_async_openai::traits::AsyncTryFrom<MyJson> for reqwest::multipart::Form {
type Error = OpenAIError;
......
......@@ -9,7 +9,7 @@
// Licensed under Apache 2.0
use dynamo_async_openai::types::CreateTranslationRequestArgs;
use dynamo_async_openai::{types::CreateTranscriptionRequestArgs, Client};
use dynamo_async_openai::{Client, types::CreateTranscriptionRequestArgs};
use tokio_test::assert_err;
#[tokio::test]
......
......@@ -48,7 +48,7 @@ pub enum DynamoLlmResult {
/// # Safety
/// the namespace_c_str and component_c_str are passed as pointers to C strings
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn dynamo_llm_init(
namespace_c_str: *const c_char,
component_c_str: *const c_char,
......@@ -108,7 +108,7 @@ pub unsafe extern "C" fn dynamo_llm_init(
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn dynamo_llm_shutdown() -> DynamoLlmResult {
let wk = match WK.get() {
Some(wk) => wk,
......@@ -123,7 +123,7 @@ pub extern "C" fn dynamo_llm_shutdown() -> DynamoLlmResult {
DynamoLlmResult::OK
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn dynamo_llm_load_publisher_create() -> DynamoLlmResult {
DynamoLlmResult::OK
}
......@@ -191,11 +191,7 @@ fn kv_event_create_stored_from_parts(
if num_toks != (kv_block_size as usize) {
if WARN_COUNT
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |c| {
if c < 3 {
Some(c + 1)
} else {
None
}
if c < 3 { Some(c + 1) } else { None }
})
.is_ok()
{
......@@ -256,7 +252,7 @@ pub struct DynamoKvStoredEventParams {
/// # Safety
/// parent_hash is passed as pointer to indicate whether the blocks
/// has a parent hash or not. nullptr is used to represent no parent hash
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn dynamo_kv_event_publish_stored(
event_id: u64,
token_ids: *const u32,
......@@ -293,7 +289,7 @@ pub unsafe extern "C" fn dynamo_kv_event_publish_stored(
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn dynamo_kv_event_publish_removed(
event_id: u64,
block_ids: *const u64,
......
......@@ -10,17 +10,17 @@ use std::{
use async_stream::stream;
use dynamo_runtime::engine::{AsyncEngine, AsyncEngineContextProvider, ResponseStream};
use dynamo_runtime::pipeline::error as pipeline_error;
use dynamo_runtime::pipeline::{async_trait, Error, ManyOut, SingleIn};
use dynamo_runtime::pipeline::{Error, ManyOut, SingleIn, async_trait};
use dynamo_runtime::protocols::annotated::Annotated;
use dynamo_runtime::{CancellationToken, ErrorContext, Result};
use llama_cpp_2::{
context::{params::LlamaContextParams, LlamaContext},
LogOptions,
context::{LlamaContext, params::LlamaContextParams},
llama_backend::LlamaBackend,
llama_batch::LlamaBatch,
model::{params::LlamaModelParams, LlamaModel},
model::{LlamaModel, params::LlamaModelParams},
sampling::LlamaSampler,
token::LlamaToken,
LogOptions,
};
use dynamo_llm::protocols::common::llm_backend::LLMEngineOutput;
......
......@@ -25,7 +25,7 @@ use dynamo_runtime::protocols::annotated::Annotated;
use dynamo_llm::protocols::openai::{
chat_completions::{NvCreateChatCompletionRequest, NvCreateChatCompletionStreamResponse},
completions::{prompt_to_string, NvCreateCompletionRequest, NvCreateCompletionResponse},
completions::{NvCreateCompletionRequest, NvCreateCompletionResponse, prompt_to_string},
embeddings::{NvCreateEmbeddingRequest, NvCreateEmbeddingResponse},
};
......@@ -240,9 +240,10 @@ impl MistralRsEngine {
}));
// Send warmup request and consume response
if let Ok(sender) = engine.mistralrs.get_sender(None) {
if let Ok(()) = sender.send(warmup_request).await {
if let Some(response) = rx.recv().await {
if let Ok(sender) = engine.mistralrs.get_sender(None)
&& let Ok(()) = sender.send(warmup_request).await
&& let Some(response) = rx.recv().await
{
match response.as_result() {
Ok(r) => {
tracing::debug!(request_id, "Warmup response: {r:?}");
......@@ -252,8 +253,6 @@ impl MistralRsEngine {
}
}
}
}
}
Ok(engine)
}
......
......@@ -4,13 +4,13 @@
use std::hint::black_box;
use std::sync::Arc;
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
use dynamo_llm::backend::Decoder;
use dynamo_llm::protocols::common::StopConditions;
use dynamo_llm::tokenizers::DecodeStream;
use dynamo_llm::tokenizers::hf::HuggingFaceTokenizer;
use dynamo_llm::tokenizers::traits::{Encoder, Tokenizer};
use dynamo_llm::tokenizers::DecodeStream;
use dynamo_llm::types::TokenIdType;
const TEST_TOKENIZER: &str = concat!(
......
......@@ -24,22 +24,22 @@ use tracing as log;
use crate::model_card::{ModelDeploymentCard, TokenizerKind};
use dynamo_runtime::{
pipeline::{
async_trait, AsyncEngineContextProvider, ManyOut, Operator, ResponseStream,
ServerStreamingEngine, SingleIn,
AsyncEngineContextProvider, ManyOut, Operator, ResponseStream, ServerStreamingEngine,
SingleIn, async_trait,
},
protocols::annotated::Annotated,
};
use crate::protocols::{
TokenIdType,
common::{
StopConditions,
llm_backend::{
BackendOutput, EmbeddingsEngineOutput, FinishReason, LLMEngineOutput,
PreprocessedRequest,
},
preprocessor::PreprocessedEmbeddingRequest,
StopConditions,
},
TokenIdType,
};
use crate::tokenizers::{DecodeStream, HuggingFaceTokenizer, Tokenizer};
use tokenizers::Tokenizer as HfTokenizer;
......@@ -149,11 +149,12 @@ impl
}
// if we have a data field without an event, then we might need to update the data
if let Some(data) = &output.data {
if data.text.is_some() && !state.validate_engine_decode {
if let Some(data) = &output.data
&& data.text.is_some()
&& !state.validate_engine_decode
{
return Some((output, state));
}
}
let data = output.data.as_ref().unwrap();
......@@ -425,8 +426,9 @@ impl Decoder {
// check stop sequences - the jail will always hold at least the largest stop sequence
// if jail_max_bytes is 0, then there are no stop sequences
if self.jail_max_bytes > 0 {
if let Some(token) = &token {
if self.jail_max_bytes > 0
&& let Some(token) = &token
{
let pre_append = self.jail.len();
log::debug!("pre_append: {}", pre_append);
log::debug!("jail: {}", self.jail);
......@@ -436,8 +438,7 @@ impl Decoder {
for seq in &self.hidden_stop_sequences {
log::debug!("stop seq: {}", seq);
if let Some(offset) =
galil_seiferas::gs_find(self.jail.as_bytes(), seq.as_bytes())
if let Some(offset) = galil_seiferas::gs_find(self.jail.as_bytes(), seq.as_bytes())
{
log::debug!("offset: {}", offset);
// return only new bytes after pre_append .. offset+seq.len()
......@@ -465,7 +466,6 @@ impl Decoder {
self.jail.drain(0..drain_len);
}
}
}
Ok(StepResult::ok(token))
}
......@@ -485,12 +485,10 @@ impl Decoder {
.map(|x| x.should_hide_text())
.unwrap_or(false);
if !hide_text {
if let Some(token) = &token {
if !hide_text && let Some(token) = &token {
text.get_or_insert_with(|| String::with_capacity(token_ids.len()))
.push_str(token);
}
}
tokens.push(token);
if let Some(stop_trigger) = stop_trigger {
......
......@@ -38,18 +38,18 @@ pub mod controller;
pub use crate::common::dtype::DType;
pub use block::{
BasicMetadata, BlockMetadata, Blocks, ImmutableBlock, MutableBlock,
locality::{self, LocalityProvider, LogicalResources},
nixl::{BlockDescriptorList, IsImmutable, IsMutable, MutabilityKind, RemoteBlock},
BasicMetadata, BlockMetadata, Blocks, ImmutableBlock, MutableBlock,
};
pub use config::*;
pub use layout::{nixl::NixlLayout, LayoutConfig, LayoutConfigBuilder, LayoutError, LayoutType};
pub use layout::{LayoutConfig, LayoutConfigBuilder, LayoutError, LayoutType, nixl::NixlLayout};
pub use offload::request::BlockResult;
pub use pool::{BlockPool, ManagedBlockPool};
pub use storage::{
nixl::NixlRegisterableStorage, DeviceStorage, DiskStorage, PinnedStorage, Storage,
StorageAllocator,
DeviceStorage, DiskStorage, PinnedStorage, Storage, StorageAllocator,
nixl::NixlRegisterableStorage,
};
pub use tokio_util::sync::CancellationToken;
......
......@@ -21,7 +21,7 @@ pub mod registry;
pub mod state;
pub mod transfer;
pub use data::{view, BlockData, BlockDataExt, BlockDataProvider, BlockDataProviderMut};
pub use data::{BlockData, BlockDataExt, BlockDataProvider, BlockDataProviderMut, view};
pub use locality::LocalityProvider;
pub use crate::tokens::TokenBlockError;
......@@ -37,10 +37,10 @@ use crate::block_manager::{
use crate::tokens::{SaltHash, SequenceHash, Token, TokenBlock, Tokens};
use super::{
WorkerID,
events::PublishHandle,
layout::{BlockLayout, LayoutError, LayoutType},
storage::StorageType,
WorkerID,
};
use derive_getters::Getters;
......@@ -657,12 +657,12 @@ impl<S: Storage, L: LocalityProvider, M: BlockMetadata> std::fmt::Debug for Muta
impl<S: Storage, L: LocalityProvider, M: BlockMetadata> Drop for MutableBlock<S, L, M> {
fn drop(&mut self) {
tracing::debug!("drop: {:?}", self);
if let Some(block) = self.block.take() {
if self.return_tx.send(block).is_err() {
if let Some(block) = self.block.take()
&& self.return_tx.send(block).is_err()
{
tracing::warn!("block pool shutdown before block was returned");
}
}
}
}
impl<S: Storage, L: LocalityProvider, M: BlockMetadata> Deref for MutableBlock<S, L, M> {
......@@ -957,9 +957,9 @@ pub mod nixl {
use super::view::{BlockKind, Kind, LayerKind};
use super::super::{
WorkerID,
layout::nixl::{NixlLayout, SerializedNixlBlockLayout},
storage::nixl::{MemType, NixlRegisterableStorage, NixlStorage},
WorkerID,
};
use derive_getters::{Dissolve, Getters};
......@@ -1360,9 +1360,7 @@ pub mod nixl {
#[error("Input block list cannot be empty")]
EmptyInput,
#[error(
"Blocks in the input list are not homogeneous (worker_id, block_set_idx mismatch)"
)]
#[error("Blocks in the input list are not homogeneous (worker_id, block_set_idx mismatch)")]
NotHomogeneous,
#[error("Serialization failed: {0}")]
......
......@@ -46,7 +46,11 @@ pub trait BlockDataExt<S: Storage>: Send + Sync + 'static + std::fmt::Debug {
fn is_local_mut(&mut self) -> Option<&mut dyn BlockDataViews<S>>;
/// Get a read-only view of this block's storage for a layer
fn layer_view(&self, layer_idx: usize, outer_idx: usize) -> BlockResult<view::LayerView<S>> {
fn layer_view(
&self,
layer_idx: usize,
outer_idx: usize,
) -> BlockResult<view::LayerView<'_, S>> {
match self.is_local() {
Some(views) => views.local_layer_view(layer_idx, outer_idx),
None => Err(BlockError::ViewsNotAvailableOnLogicalBlocks),
......@@ -58,7 +62,7 @@ pub trait BlockDataExt<S: Storage>: Send + Sync + 'static + std::fmt::Debug {
&mut self,
layer_idx: usize,
outer_idx: usize,
) -> BlockResult<view::LayerViewMut<S>> {
) -> BlockResult<view::LayerViewMut<'_, S>> {
match self.is_local_mut() {
Some(views) => views.local_layer_view_mut(layer_idx, outer_idx),
None => Err(BlockError::ViewsNotAvailableOnLogicalBlocks),
......@@ -66,7 +70,7 @@ pub trait BlockDataExt<S: Storage>: Send + Sync + 'static + std::fmt::Debug {
}
/// Get a read-only view of this block's storage
fn block_view(&self) -> BlockResult<view::BlockView<S>> {
fn block_view(&self) -> BlockResult<view::BlockView<'_, S>> {
match self.is_local() {
Some(views) => views.local_block_view(),
None => Err(BlockError::ViewsNotAvailableOnLogicalBlocks),
......@@ -74,7 +78,7 @@ pub trait BlockDataExt<S: Storage>: Send + Sync + 'static + std::fmt::Debug {
}
/// Get a mutable view of this block's storage
fn block_view_mut(&mut self) -> BlockResult<view::BlockViewMut<S>> {
fn block_view_mut(&mut self) -> BlockResult<view::BlockViewMut<'_, S>> {
match self.is_local_mut() {
Some(views) => views.local_block_view_mut(),
None => Err(BlockError::ViewsNotAvailableOnLogicalBlocks),
......@@ -88,20 +92,20 @@ pub trait BlockDataViews<S: Storage> {
&self,
layer_idx: usize,
outer_idx: usize,
) -> BlockResult<view::LayerView<S>>;
) -> BlockResult<view::LayerView<'_, S>>;
/// Get a mutable view of this block's storage for a layer
fn local_layer_view_mut(
&mut self,
layer_idx: usize,
outer_idx: usize,
) -> BlockResult<view::LayerViewMut<S>>;
) -> BlockResult<view::LayerViewMut<'_, S>>;
/// Get a read-only view of this block's storage
fn local_block_view(&self) -> BlockResult<view::BlockView<S>>;
fn local_block_view(&self) -> BlockResult<view::BlockView<'_, S>>;
/// Get a mutable view of this block's storage
fn local_block_view_mut(&mut self) -> BlockResult<view::BlockViewMut<S>>;
fn local_block_view_mut(&mut self) -> BlockResult<view::BlockViewMut<'_, S>>;
}
pub trait BlockDataProvider: StorageTypeProvider {
......
......@@ -101,7 +101,7 @@ impl<S: Storage> BlockDataViews<S> for LocalBlockData<S> {
&self,
layer_idx: usize,
outer_idx: usize,
) -> BlockResult<view::LayerView<S>> {
) -> BlockResult<view::LayerView<'_, S>> {
let mr = self
.layout
.memory_region(self.block_idx, layer_idx, outer_idx)?;
......@@ -113,14 +113,14 @@ impl<S: Storage> BlockDataViews<S> for LocalBlockData<S> {
&mut self,
layer_idx: usize,
outer_idx: usize,
) -> BlockResult<view::LayerViewMut<S>> {
) -> BlockResult<view::LayerViewMut<'_, S>> {
let mr = self
.layout
.memory_region(self.block_idx, layer_idx, outer_idx)?;
unsafe { view::LayerViewMut::new(self, mr.addr(), mr.size(), mr.storage_type()) }
}
fn local_block_view(&self) -> BlockResult<view::BlockView<S>> {
fn local_block_view(&self) -> BlockResult<view::BlockView<'_, S>> {
if self.is_fully_contiguous() {
let mr = self.layout.memory_region(self.block_idx, 0, 0)?;
let offset = mr.addr();
......@@ -134,7 +134,7 @@ impl<S: Storage> BlockDataViews<S> for LocalBlockData<S> {
}
}
fn local_block_view_mut(&mut self) -> BlockResult<view::BlockViewMut<S>> {
fn local_block_view_mut(&mut self) -> BlockResult<view::BlockViewMut<'_, S>> {
if self.is_fully_contiguous() {
let mr = self.layout.memory_region(self.block_idx, 0, 0)?;
let offset = mr.addr();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment