ValarMorghulis.IO (original) (raw)

Run MiniCPM4 with CPU only

2025-06-08

This is a guide for serving the MiniCPM4 0.5b model with CPU only(in my laptop WSL Ubuntu 24.04). The model is served by llama.cpp, and I break down it for several steps. Download the model from hf huggingface-cli download openbmb/MiniCPM4-0.5B Install(and compile) the llama.cpp # build llama.cpp git clone https://github.com/ggml-org/llama.cpp.git sudo apt install python3-dev build-essential cmake libcurl4-openssl-dev cmake -B build cmake --build build --config Release # prepare llama tools uv venv --python=3.Continue reading

Call MCP Server(stdio) directly in the shell

2025-05-19

stdio is one of the transport mechanisms MCP(Model Context Protocol) natively supports. Actually stdio is the only transport mechanism Claude Desktop supports currently(as in May, 2025). This article will show you how to call a MCP server in the shell, without mcp dev or any third party tools, only with echo > or copying/pasting JSONRPC message directly. First, let’s write a very simple MCP server(get_time.py) to get the current time:Continue reading

Measuring the CPU and Memory Usage for Python subprocess

2025-05-14

The article talks about a method for measuring the resources used by a process invoked by subprocess.run or subprocess.Popen. We can use psutil to get realtime usage data of a process. Using psutil may not provide accurate resource measurements for short-lived processes, as it samples usage at intervals and can miss brief spikes. We want a method to get the final resource usage of a process after it finishes. The method leverages multiprocessing.Continue reading

tac -- the ignored reverse of cat

2025-03-18

When grep a very large log file to find the last occurrence of some string, it is much than efficient to back iterate the files from the last line than methods using tail or tail -n. And I just found tac from coreutils, best suiting the job. tac is the reverse of cat, the job I mentioned above can be done via: tac very-large-log-file.log|grep -m 1 some-string This is very useful.Continue reading

Python version of Rust Result Sum Type

2025-01-19

I try to implement a Python version of the Result<T, E> sum type in rust which can be used with match/case pattern matching. The pattern matching with sub-patterns like case Err(e) could be implemented in Python with the __match_args__ dunder attribute. This is how Result[T, E], OK() and Err() defined: import typing T = typing.TypeVar('T') E = typing.TypeVar('E') class Result[T, E]: __match_args__ = ('_val',) def __init__(self, val): self._val = val class Ok[T](Result[T, .Continue reading

Run wasm built with wasm-pack with pythonmonkey

2025-01-03

I have been trying to run wasm code built with wasm-pack with pythonmonkey, a Mozilla SpiderMonkey JavaScript engine embedded into the Python Runtime. Consider a lib.rs as follow: use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn add(a: i32, b: i32) -> i32 { return a + b; } With wasm-pack, we can build the src code to wasm wasm-pack build --target nodejs --no-typescript We will get a .wasm file and a .js wrapper file.Continue reading

Combine mesop with natural abilities of flask

2024-12-23

mesop is popular with AI apps, since is can be used to build web apps with Python without frontend works. mesop is developed upon the popular frontend framework flask. How about combine the natural abilities of flask while developing with mesop? Let do a little research. Access flask request instance(including headers, cookies) In any mesop page, you may simply access flask.request, flask.request.cookies, flask.request.headers by importing flask. For example import flask import mesop as me @me.Continue reading