Skip to content

Commit

Permalink
remove "meta" field on uploaded controllers (was unused anyways)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Jan 12, 2024
1 parent 30ebfbe commit 40b83d2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 46 deletions.
4 changes: 0 additions & 4 deletions aicirt/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,12 @@ impl<T> SequenceResult<T> {
#[derive(Serialize, Deserialize)]
pub struct MkModuleReq {
pub binary: String,
#[serde(default)]
pub meta: Value,
}

#[derive(Serialize, Deserialize)]
pub struct MkModuleResp {
pub module_id: String,
pub wasm_size: usize,
pub meta_size: usize,
pub compiled_size: usize,
pub time: u64,
}
Expand All @@ -139,7 +136,6 @@ pub struct TagInfo {
pub updated_at: u64, // unix time
pub updated_by: String,
pub wasm_size: u64,
pub meta_size: u64,
pub compiled_size: u64,
}

Expand Down
36 changes: 5 additions & 31 deletions aicirt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ struct Cli {
#[arg(short, long)]
module: Option<String>,

/// Path to .json metadata for module to install
#[arg(short = 'j', long)]
module_meta: Option<String>,

/// Tokenizer to use; try --tokenizer list to see options
#[arg(short, long, default_value = "llama")]
tokenizer: String,
Expand Down Expand Up @@ -184,10 +180,6 @@ impl ModuleRegistry {
}
}

fn meta_path(&self, module_id: &str) -> PathBuf {
self.cache_path.join(format!("{}.json", module_id))
}

fn sys_meta_path(&self, module_id: &str) -> PathBuf {
self.cache_path.join(format!("{}-sys.json", module_id))
}
Expand Down Expand Up @@ -244,26 +236,17 @@ impl ModuleRegistry {
Ok(self.elf_path(module_id))
}

fn create_module(
&self,
wasm_bytes: Vec<u8>,
meta_bytes: Vec<u8>,
auth: AuthInfo,
) -> Result<Value> {
fn create_module(&self, wasm_bytes: Vec<u8>, auth: AuthInfo) -> Result<Value> {
let timer = Instant::now();

// make sure meta_bytes is valid JSON
let _: Value = serde_json::from_slice(&meta_bytes)?;

let mut hasher = Sha256::new();
hasher.update(&meta_bytes);
let mut hasher = <Sha256 as Digest>::new();
hasher.update(&wasm_bytes);

let module_id = hex::encode(hasher.finalize());
let module_id = &module_id;

if self.module_needs_check(module_id) {
match self.write_and_compile(module_id, &meta_bytes, &wasm_bytes, &auth) {
match self.write_and_compile(module_id, &wasm_bytes, &auth) {
Err(e) => {
let mut lck = self.modules.lock().unwrap();
lck.remove(module_id);
Expand All @@ -287,7 +270,6 @@ impl ModuleRegistry {
Ok(serde_json::to_value(MkModuleResp {
module_id: module_id.to_string(),
wasm_size: wasm_bytes.len(),
meta_size: meta_bytes.len(),
compiled_size,
time,
})?)
Expand All @@ -296,13 +278,11 @@ impl ModuleRegistry {
fn write_and_compile(
&self,
module_id: &String,
meta_bytes: &Vec<u8>,
wasm_bytes: &Vec<u8>,
auth: &AuthInfo,
) -> Result<()> {
fs::create_dir_all(&self.cache_path)?;
Ok(if !self.wasm_path(module_id).exists() {
fs::write(self.meta_path(module_id), meta_bytes)?;
fs::write(self.wasm_path(module_id), wasm_bytes)?;
fs::write(
self.sys_meta_path(module_id),
Expand All @@ -319,8 +299,7 @@ impl ModuleRegistry {

fn mk_module(&self, req: MkModuleReq, auth: AuthInfo) -> Result<Value> {
let wasm_bytes = base64::engine::general_purpose::STANDARD.decode(req.binary)?;
let meta_bytes = serde_json::to_vec(&req.meta)?;
self.create_module(wasm_bytes, meta_bytes, auth)
self.create_module(wasm_bytes, auth)
}

fn set_tags(&self, req: SetTagsReq, auth: AuthInfo) -> Result<Value> {
Expand Down Expand Up @@ -358,7 +337,6 @@ impl ModuleRegistry {
updated_at: get_unix_time(),
updated_by: auth.user.clone(),
wasm_size: self.wasm_path(&req.module_id).metadata()?.len(),
meta_size: self.meta_path(&req.module_id).metadata()?.len(),
compiled_size: self.elf_path(&req.module_id).metadata()?.len(),
};

Expand Down Expand Up @@ -1063,13 +1041,9 @@ fn install_from_cmdline(cli: &Cli, wasm_ctx: WasmContext, shm: Shm) {
name.to_string()
} else {
let wasm_bytes = fs::read(name).unwrap();
let meta_bytes = match cli.module_meta.as_deref() {
Some(name) => fs::read(name).unwrap(),
None => serde_json::to_vec(&Value::Null).unwrap(),
};

let json = reg
.create_module(wasm_bytes, meta_bytes, AuthInfo::local_user())
.create_module(wasm_bytes, AuthInfo::local_user())
.unwrap();
json["module_id"].as_str().unwrap().to_string()
};
Expand Down
2 changes: 1 addition & 1 deletion harness/vllm_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def check_length(
@app.post("/v1/aici_modules")
async def upload_aici_module(request: Request):
contents = await request.body()
return await aici.upload_module_async(contents, {})
return await aici.upload_module_async(contents)


@app.get("/v1/models")
Expand Down
2 changes: 1 addition & 1 deletion pyaici/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def main_inner():
"-c",
metavar="MODULE_ID",
type=str,
help="tag name or hex module id",
help="tag name or hex module id (sha256 of .wasm file)",
)
run_cmd.add_argument(
"--upload",
Expand Down
4 changes: 2 additions & 2 deletions pyaici/comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ def replay(self, prev_trace: str):
ch.send(obj["cmd"])
ch.expect("replay")

async def upload_module_async(self, wasm: bytes, meta={}):
async def upload_module_async(self, wasm: bytes):
b64 = base64.b64encode(wasm).decode("utf-8")
return await self.side_cmd.exec_async(
"mk_module", {"binary": b64, "meta": meta}
"mk_module", {"binary": b64}
)

async def instantiate_async(
Expand Down
8 changes: 1 addition & 7 deletions rllm/src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,7 @@ async fn upload_aici_module(
let binary = base64::engine::general_purpose::STANDARD.encode(body);
let r = data
.side_cmd_ch
.mk_module(
MkModuleReq {
binary,
meta: serde_json::Value::Null,
},
auth_info(&req),
)
.mk_module(MkModuleReq { binary }, auth_info(&req))
.await
.map_err(APIError::just_msg)?;
Ok(web::Json(r))
Expand Down

0 comments on commit 40b83d2

Please sign in to comment.