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
impl Server
Sourcepub fn new() -> Self
pub fn new() -> Self
A server with ServerConfig::default: 127.0.0.1:3000, batching off (see
max_batch_size)
pub fn with_config(config: ServerConfig) -> Self
pub fn host(self, host: &str) -> Self
pub fn port(self, port: u16) -> Self
Sourcepub fn max_batch_size(self, items: usize) -> Self
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
Sourcepub fn request_timeout(self, timeout: Duration) -> Self
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)
Sourcepub fn configure(self, change: impl FnOnce(&mut ServerConfig)) -> Self
pub fn configure(self, change: impl FnOnce(&mut ServerConfig)) -> Self
Change any other setting
Sourcepub fn model(self, model: Model) -> Self
pub fn model(self, model: Model) -> Self
Serve model; the first model added is the one /predict uses
Sourcepub fn nerve(self, fabric: FabricBuilder) -> Self
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.
Sourcepub fn reloadable_model(
self,
model: Model,
reload: impl Fn(Option<&Path>) -> Result<Model> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn router(self) -> Result<Router>
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>(),
)
.awaitTrait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Server
impl !UnwindSafe for Server
impl Freeze for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request