用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill rust-ml命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
| Use when this capability is needed.
> Use when this capability is needed.
Review architecture and API design for the vfs-s3 project. Use when the user mentions @architect, asks to review an issue's design, discuss module boundaries, API shape, or architectural decisions for vfs-s3. Also trigger when the user wants to create an ADR (Architecture Decision Record) or evaluate a technical approach for the project. Intended for dispatch from Codex automation or Claude routines; GitHub trigger phrase: @vfs-s3-bot please prepare design doc Use when this capability is needed.
正在显示 SKILL.md
基于 SOC 职业分类
| name | rust-ml |
| description | | Use when this capability is needed. |
Strategies for high-performance numerical computing and model inference in Rust.
Avoid writing manual parsing and filtering loops. Use polars for lightning-fast, multi-threaded columnar data operations.
use polars::prelude::*;
fn analyze_data() -> Result<DataFrame, PolarsError> {
// Read CSV, select columns, filter rows, and execute lazily
LazyCsvReader::new("data.csv")
.has_header(true)
.finish()?
.select([col("age"), col("salary"), col("department")])
.filter(col("age").gt(30))
.groupby([col("department")])
.agg([col("salary").mean().alias("avg_salary")])
.collect()
}
Use ndarray for multidimensional arrays, vector arithmetic, and linear algebra.
use ndarray::{array, Array2, Array, IxDyn};
// Create a 2D matrix
let matrix_a: Array2<f64> = array![
[1.0, 2.0],
[3.0, 4.0]
];
let matrix_b: Array2<f64> = array![
[2.0, 0.0],
[1.0, 2.0]
];
// Perform matrix multiplication
let result = matrix_a.dot(&matrix_b);
// Dynamic-dimensional tensor for variable shapes
let dynamic: Array<f64, IxDyn> = Array::from_shape_vec(
IxDyn(&[2, 3, 4]),
(0..24).map(|x| x as f64).collect(),
)?;
candle: HuggingFace's minimalist tensor library, optimized for lightweight CPU/GPU model inference (LLMs, Whisper, etc.).burn: Flexible, production-grade deep learning framework supporting both training and inference with type-safe backend abstractions (WGPU, LibTorch, WebGPU).ort: ONNX Runtime bindings for models exported from PyTorch, TensorFlow, or scikit-learn.tract: Inference engine for ONNX and TensorFlow models, optimized for embedded/low-latency.| Framework | Best For | GPU Support | Training | Model Format |
|---|---|---|---|---|
| Candle | Inference, LLMs | CUDA | No | SafeTensors, GGML |
| Burn | Full training & inference | WGPU, LibTorch, Vulkan | Yes | Native format, ONNX |
| ORT | ONNX model deployment | CUDA, DirectML | No | ONNX |
| Tract | Embedded, low-latency | CPU only | No | ONNX, TF |
| Tch-rs | PyTorch bindings | CUDA | Yes | PyTorch checkpoint |
use candle_core::{Device, Tensor};
fn run_inference() -> candle_core::Result<()> {
let device = Device::Cpu;
// Create inputs from slices
let x = Tensor::new(&[1.0f32, 2.0f32, 3.0f32, 4.0f32], &device)?;
// Perform operations
let y = x.mul(2.0)?;
println!("Output: {:?}", y.to_vec1::<f32>()?);
Ok(())
}
use ort::{Environment, Session, Value, inputs};
fn run_onnx(model_path: &str) -> ort::Result<()> {
let environment = Environment::builder()
.with_name("inference_env")
.build()?;
let session = Session::builder()?
.with_model_from_file(model_path)?;
let input_tensor = Value::from_tensor(
ndarray::Array::from_shape_vec(
(1, 3, 224, 224),
vec![0.0f32; 3 * 224 * 224],
)?
)?;
let outputs = session.run(inputs!["input" => input_tensor]?)?;
Ok(())
}
Keep model weights out of memory allocations during parsing. Load model weights using Memory Maps (memmap2) to let the OS handle virtual memory paging efficiently.
use memmap2::Mmap;
pub struct ModelWeights {
data: Mmap,
}
impl ModelWeights {
pub fn from_file(path: &str) -> Result<Self, Box<dyn std::error::Error>> {
let file = std::fs::File::open(path)?;
// SAFETY: file is not modified while mapped; data is read-only.
let data = unsafe { Mmap::map(&file)? };
Ok(Self { data })
}
pub fn get_slice(&self, offset: usize, len: usize) -> &[u8] {
&self.data[offset..offset + len]
}
}
use polars::prelude::*;
fn build_features(path: &str) -> Result<DataFrame, PolarsError> {
LazyCsvReader::new(path)
.has_header(true)
.finish()?
.filter(col("label").is_not_null())
.with_column(
col("timestamp")
.str()
.to_datetime(None, None, lit(""),
StrptimeOptions::default())
.alias("parsed_ts")
)
.with_column(
(col("feature_a") - col("feature_a").mean())
/ col("feature_a").std()
.alias("feature_a_scaled")
)
.select([
col("feature_a_scaled"),
col("feature_b"),
col(),
])
.()
}
use std::sync::Arc;
pub struct InferenceService {
model: Arc<ModelWeights>,
config: ModelConfig,
}
impl InferenceService {
pub fn new(model_path: &str, config: ModelConfig) -> Result<Self, Error> {
let model = ModelWeights::from_file(model_path)?;
Ok(Self { model: Arc::new(model), config })
}
pub async fn predict(&self, input: &[f32]) -> Result<Vec<f32>, Error> {
// Batch input validation
if input.len() != self.config.input_size {
return Err(Error::InvalidInputShape);
}
// Run inference (could be spawned on a dedicated thread for CPU-bound work)
let model = self.model.clone();
let config = self.config.clone();
let result = tokio::task::spawn_blocking( || {
(&model, &config, input)
}).??;
(result)
}
}
Key points:
rayon for data-parallel preprocessing.cargo flamegraph to find actual bottlenecks before optimizing.// Bad: loading a model per request.
async fn handle(req: Request) -> Response {
let model = load_model("model.bin").await?; // expensive I/O on every call
predict(model, req).await
}
// Good: load once at startup, share via Arc.
static MODEL: OnceLock<Arc<InferenceService>> = OnceLock::new();
// Bad: serializing the full dataframe to JSON for every response.
let json = serde_json::to_string(&df)?;
// Good: convert only what the client needs.
let summary = df.select(&["id", "score"])?.head(Some(100));
For Rust ML, check data schema, preprocessing parity, model loading lifecycle, batch/latency tradeoff, backend choice, and observability for model version and drift.
When the answer depends on library choice, first identify constraints: latency budget, data size, deployment target, auditability, and team familiarity. Then recommend the smallest tool that satisfies the constraint instead of the most powerful tool.
When explaining this topic to a user, start with the invariant, show the safe/default approach, then mention advanced alternatives only when the user's constraints justify them.
Source: adxptived/Rust-Skills — distributed by TomeVault.