Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

Serve your own models from Rust, with everything the furnace binary does: dynamic batching, the Open Inference Protocol over HTTP (and gRPC), metrics, readiness, reloads, API keys, rate limits and TLS, all configured through ServerConfig.

ⓘ
// A Burn model's forward function, through furnace-burn
let model = furnace_burn::from_fn("digits", BackendKind::Cpu, &[1, 28, 28], &[10],
    move |x: Tensor<4>| net.forward(x))?;
Server::new().port(8080).model(model).serve().await?;

Server::router gives the HTTP API as an axum Router instead, to mount in your own application.

Implementations§

Source§

impl Server

Source

pub fn new() -> Self

A server with ServerConfig::default: 127.0.0.1:3000, batching off (see max_batch_size)

Source

pub fn with_config(config: ServerConfig) -> Self

Source

pub fn host(self, host: &str) -> Self

Source

pub fn port(self, port: u16) -> Self

Source

pub fn max_batch_size(self, items: usize) -> Self

The most items one batch carries, for the dynamic batching of concurrent requests (BatchConfig::max_batch_size); 1 turns batching off

Source

pub fn request_timeout(self, timeout: Duration) -> Self

How long one inference may take before its request gets 504 Gateway Timeout (ServerConfig::request_timeout; none by default)

Source

pub fn configure(self, change: impl FnOnce(&mut ServerConfig)) -> Self

Change any other setting

Source

pub fn model(self, model: Model) -> Self

Serve model; the first model added is the one /predict uses

Source

pub fn llm(self, engine: impl LlmEngine) -> Self

Serve an LLM (feature llm) on POST /v1/chat/completions, POST /v1/completions and GET /v1/models, next to the other models: a Scheduled step model, or any LlmEngine, or an Arc of one shared with a nerve Llm. A request without model goes to the first LLM added.

Source

pub fn nerve(self, fabric: FabricBuilder) -> Self

Add neurons of your own to the server’s nervous system; a fabric that cannot be built makes serve and router return FurnaceError::Nerve. The server wires its models into the same fabric (an entrance in:{model}, a neuron model:{model} and the serve:respond effector), so your pathways and its requests share one system. The HTTP receptors become routes, the receptors start with the server, GET /nerve describes every neuron, pathway and measured latency, GET /nerve/effectors/{name}/events streams an SSE effector’s commands, and /metrics carries it all. A server may serve your neurons alone.

Source

pub fn reloadable_model( self, model: Model, reload: impl Fn(Option<&Path>) -> Result<Model> + Send + Sync + 'static, ) -> Self

Serve model and let POST /admin/models/{name}/reload replace it with what reload returns (given the request’s weights path, if any). Needs an admin token in the config.

Source

pub fn router(self) -> Result<Router>

The HTTP API as an axum router, to serve or mount yourself, or an error for a server with nothing to serve, as serve gives.

A rate limit without API keys tells clients apart by their address, which axum knows only when the router is served with ClientAddr as connect info; otherwise every client shares one budget:

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(
    listener,
    app.into_make_service_with_connect_info::<furnace::api::ClientAddr>(),
)
.await
Source

pub async fn serve(self) -> Result<()>

Serve until Ctrl-C / SIGTERM

Trait Implementations§

Source§

impl Default for Server

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more