Skip to content

Latest commit

 

History

History
123 lines (84 loc) · 27.3 KB

README.md

File metadata and controls

123 lines (84 loc) · 27.3 KB

driver

Two Python scripts around a proving service. A client needs neither to check a proof: a client calls cp_verify itself (../verifier/README.md). Words: "status", "folder" and "refuse" on this page mean what the pages under docs/ call exit code, directory and reject. The page's sentences were compared once with measure_rate.py, with spool.py (all but others_can_change()) and with the head of ../prover/prover/spool.h and the parts of it that this page names, in a text from which this page differs in places: a sentence that is not in that text was not compared. That comparison found sentences of that text false; none of them stands on this page in that form.

What is in this folder

file who runs it read next
spool.py: builds a request file; submits requests to a service and reads its responses a client, to build a request; an operator's front-end program, for the rest The spool
measure_rate.py: starts a service on a commitment, gives it full batches, has every proof checked and prints the steady rate of proving whoever wants to measure the prover's speed on a machine of their own The rate

No clock and no verifier on another machine. measure_rate.py takes its times from outside cp_prove, as the kernel's change times of the files in out/, and has every proof checked by a separate call of cp_verify. But the clock, the kernel and the verifier are those of the prover's own machine, under the account that runs the prover. No tool of this repository ties a speed figure to a clock or a verifier on another machine. Limits that bear on a front end and on its clients stand in ../verifier/README.md, ../verifier/docs/parameter-file.md, ../docs/operators-duties.md, ../docs/what-is-not-hidden.md, and below under "If the spool directory has stood open".

The spool

spool.py builds request files, and is a front-end program's side of a proving service's spool directory. No client may reach the spool directory: a front end must stand between the clients and it. The rules of the spool directory are in The prover as a service, "What your program must do" and "The files".

The tag, <id>.tag, ties a response's files to its id, under a key derived from the request file's nonce alone (The tag). Whoever holds that key can make a tag: the service and a front end. The tag is for the front end alone: hand it to no client. cp_prove with -in and -out (one batch) writes no tag.

From a shell:

  • python3 driver/spool.py request <T> <prompt file> <reply file> <end token's id, or none> <request file to write> writes a request that covers the whole reply and prints its covered positions as r:e. Give cp_verify the file that it writes. The prompt and reply files hold token ids as little-endian 32-bit words. It appends the end token if the reply does not end with it. (docs/verifying.md prints another command for a client, python3 integrations/spool.py make-request: that one reads token ids as decimal numbers, rejects a reply that does not end with the end token, and checks the directories above the file that it writes. Both pad with token 0; neither can stand in for the other.) It fails if the request file exists, if prompt and reply do not fit into T tokens, or if the end token occurs earlier in the reply. Use a new name, or a new, empty folder, for each check. If the command fails, stop: a call of cp_verify with the old file's name would judge the earlier request.
  • python3 driver/spool.py lay <spool directory> <request file> submits a request and prints its id. The spool directory must exist: a path that does not exist is refused and nothing is made, so that a mistyped path does not become a folder that no service reads. It appends 32 random bytes (a nonce) to the request, so the file in the spool directory is not the file that cp_verify takes. A proof's first hash takes the request's words alone, not these 32 bytes, and cp_verify refuses a spool's file that is handed to it as it lies (statement-range, by a reading of the code). The front end must itself keep that id, filed under the client that sent the request, and give the response to that client alone (Operator's duties, "The front end"). The one example front end in this repository, a middleware for vLLM, knows proof IDs, not clients, and breaks several of the rules for a front end (which; its limits).

From Python, the module has request(tokens, first, end), whole_reply(), lay(), answered(), wait_for(), read_member(), stop() and tag_key(). A limit, in the words of spool.py's head: "A front end that serves clients should not trust the path to the spool directory: an account that can write in a directory on that path can put another directory there. lay(), read_member() and the other functions that take a path do not walk it one directory at a time without following links, so they would not notice. Such a front end must bring its own functions for that: this module has none."

What a front end does with the tag

  1. Submit each request with lay(<spool directory>, <request>, with_key=True). It returns the id and the tag's key. Keep both on your side, filed under the client that sent the request.
  2. Before the first reading, call private_folders(<spool directory>, "out") once: it raises PermissionError if out/ is a symbolic link or another user's folder (and creates a missing one). read_member() and answered() do not check out/ itself and use such a folder all the same. Then read the response with read_member(<spool directory>, <id>, key=<key>). It opens each file once and compares the tag with the id and the bytes that it read. If the returned faults list is not empty, hand the response to nobody. An empty list says nothing of the proof: check it first. It also reports a tag that another account owns: run this part under the service's account.
  3. read_member() returns each file's SHA-256, not its bytes. If you then read a file by its path, compare it with that SHA-256: names in out/ can change after the reading.
  4. Keep the key out of every log and message.

Without a key (the shell's lay gives none), read_member() checks only the tag's form, and the response may be another request's.

What the tag is for, in the words of spool.py: "Without it, an account that cannot read a response but can exchange names in out/ could bring a front end to hand one client's response to another." The tag ties the files to the id from the moment at which the service makes it, directly before the naming: files exchanged in the service's staging folder before then get fitting tags, and only a verifier run on each response stands against them. It does not protect against the service's own account, against root, or against anyone who can read the request file; a relay through which a request went holds its nonce, and so can make its tag. It does nothing for whoever fetches files past the front end, and it says nothing on whether a proof is right.

If the spool directory has stood open. The request file itself, which lies in in/ and then in work/ until the response is on the disk, ends with the nonce that gives the tag's key: a request file that was readable gives away as much. Whoever could read one, in a spell in which the spool directory stood open to another account, holds id and key for as long as the front end knows that request. With them, and a way to put bytes of its choice into a tag file of the service's own in out/ (the file stood open for writing too, or a descriptor has been kept open since), it makes a fitting tag for any bytes under that id. Then a false failed, or another client's response under a new tag, passes the front end. A front end that takes id and key from a file which that account can rewrite hands the response out to it with no write in out/. chmod alone heals nothing. Stop the service and the front end; make a new spool directory (mkdir -m 700) and move nothing over; delete or clean the front end's records of every request that waited during the spell.

A front end's other duties

Among them (the second, the third and the first sentence of the sixth are proposed, not tried; more of them: ../docs/service.md, "What your program must do", and ../docs/operators-duties.md, "The front end"):

  • Before you give out any response of a batch, a failed too, check every proof of that batch with a cp_verify that you built and keep where the service's account cannot write. Give it the published files and policy, the commitment ID from your own record (-id) and your own copy of the request. Read each response once, check those bytes and give out those bytes. Give out none of the batch unless every check ends with status 0 and the last line YES (under a clipped-gap policy that you name with -policy, if the request covers more than the one answered token: WITHIN LIMITS: clipped-gap C=<C> theta=<theta> cap=<cap> s=<s> sh=<sh>, with your own numbers), and, if you do not accept work, with the line proof of work: none counted above it (under every configuration of prover/examples/ work is counted, and that line says how much; whether work counts is your decision: ../verifier/README.md), and keep a lasting record of every NO (After a refusal or a fault).
  • Keep one record for each commitment, only added to, on a system that neither commits nor proves, outside their backups. Add one to it for each request before you submit it, and again each time you submit it again; spool.py counts nothing. Let requests reach the prover only through front ends that share that record, also when you submit them with this folder's script (what the programs themselves count: The count).
  • After a NO from your check, two runs of your check on one response that end with no answer, or any end of cp_prove but status 0 with its last line p258 end 0: submit nothing more, and give out nothing more that the prover's machine has made or makes under this commitment, not even an accepted response or a failed. Only a person lifts this hold (After a refusal or a fault).
  • Let no program start the service again by itself. A service that ended after a release, before all of that batch's requests have left work/, and is started again withdraws the responses whose requests it still finds there and answers each of them with failed, and the rest of their batch stays in out/ without them (../prover/prover/spool.h, open() and withdraw(): by reading).
  • Remove a response's files once it is delivered (../prover/prover/spool.h's head asks it of the front end), in this order: .proof or .failed first, so that nobody beside you finds a response that looks complete and is not; then the tag; .y last. A tag that outlives its response keeps, for whoever lists out/, a record that this id was answered, and when. No function of spool.py does this for you.
  • Give each client only the bytes of the responses to its own requests: no listings, file times, ids or access to the staging folder, out/.tmp/ (The front end). Timing is not hidden (what a client learns from time). Pass on neither the tick_ns that read_member() returns (a file time: the moment at which the service releases the batch) nor the ids that answered() returns.
  • Turn away requests that you do not mean to answer, such as stretches that probe which tokens the model would choose; no verifier or prover enforces it, and nothing shows a client whether you do it. Under a score policy, prove only replies that you served, over stretches that you set, and refuse serving options that let a client fix or restrict the reply's tokens; this narrows the leak without ending it.
  • Treat the spool directory's disk like the secret key folder at all times. Let no other account write or link in the spool directory or its staging folder (After a refusal or a fault). spool.py says of private_folders(): "A process that only reads responses should call private_folders(spool, "out") once, and one that only creates the stop file private_folders(spool), before it trusts what it finds there."

The rate

measure_rate.py measures how fast a production build of cp_prove proves, from outside the program. It needs what the programs need, one GPU among it, and a commitment. The steady rate is a batch's requests times T tokens, divided by the mean interval between the releases of successive batches; a batch's release is the latest change time of its proof files in out/. guide/performance.md reports what this rule gives on one NVIDIA H100 80 GB at 24 requests in a batch and 6 in each pass over the weights, measured by other scripts, which do not ship.

python3 driver/measure_rate.py --programs B --isk ISK --ivk IVK --config CONFIG --id ID --work NEW_DIRECTORY

Replace the words in capitals. B, ISK, IVK, CONFIG and ID are those of Operator's duties, "From nothing to the first proof": the directory with the programs, the secret and the public key directory, the configuration directory, and the commitment ID from your own record of what cp_commit printed. NEW_DIRECTORY is the work directory. It must not exist yet, or be an empty directory of yours with mode 0700, below directories that no other account can change, and outside the other directories that the call names. Its full path may have at most 390 characters, all of them letters, digits or / . _ -.

In order, the script:

  1. prints what machine it found: the GPU that it asks nvidia-smi about (the first that CUDA_VISIBLE_DEVICES names, or GPU 0), its driver and memory, and, unless CUDA_DEVICE_ORDER=PCI_BUS_ID is set, a warning that on a machine with GPUs of different models the programs may take another GPU; the CPUs that it may use and the GPU's NUMA node; the host memory, the container's limit and what is available now; the free room on the work directory's file system; Linux's setting for transparent huge pages; VERSION; the SHA-256 of cp_prove, of cp_verify and of the three configuration files;
  2. makes N times B requests of T tokens, each asking only for the token after its window;
  3. submits all of them to a new spool directory below the work directory, before the service starts, so that every batch is full;
  4. starts cp_prove once, with -most-batches N, so that the service ends by itself, and prints its process ID; HOME and TMPDIR are two new directories below the work directory;
  5. looks at the spool directory about ten times a second and notes when each request leaves in/ and when its response appears in out/; once a second it asks nvidia-smi for the memory in use on that one GPU;
  6. after cp_prove has ended, checks each response's tag, and has each proof checked by a separate, whole call of cp_verify, with your commitment ID, the script's own copy of the request and the token that the response itself names;
  7. prints the figures, and writes them to the work directory with every time that they rest on.
option what it sets default
--batch B requests in a batch (cp_prove -batch) 24
--in-step K requests in one pass over the weights (-in-step) 6, or B if B is smaller
--batches N batches (-most-batches), at least 3; N times B at most 100,000 5
--memory WORDS -memory; an empty text leaves the option out lean,tensor-rooms=8
--least-memory GB start nothing unless so many GB (10^9 bytes) of host memory are available, on the machine and under the container's limit, with file cache counted as available no such check
--public-weights FILE, --huge-pages passed on to cp_prove; with -public-weights nothing is hidden (Public weights) not given
--text FILE make the windows from this file's rows of token ids: a NumPy file (format 1.0, little-endian int32, C order) of rows of T ids, such as the file that scales/make_calibration_set.py writes the script draws them
--requests DIR take the requests from this directory's files, in the order of their names: at least N times B different files, each T tokens, then r = T - 1 and e = T the script draws them
--seed n the seed of the windows that the script draws 1
--checks-at-once n calls of cp_verify side by side, each with -j 4; at most the CPUs that the script may use a quarter of these CPUs, at least 1 and at most 6

The first four rows set options of cp_prove, and not all to its own defaults: for example, -batch and -in-step are 1 unless they are given (Serve).

The windows. By default the script draws its windows, random token ids, by a rule that its head states, from a seed that it prints, so a second run sends the same ones. With --text FILE the windows are that file's rows, by a rule that the head also states and the script prints, with the file's SHA-256. It refuses a file of another kind, anything that is not a regular file, and a row with an id that is not below the vocabulary size. The requests in the work directory then hold that file's token ids: whoever hands the work directory on hands that text on, under the text's own licence (the file that scales/make_calibration_set.py writes holds text from the training split of WikiText-2: examples/maverick/README.md). Whatever their source, the script sends no window twice, and it claims nothing on whether a batch's time depends on which tokens the batch holds.

What it prints. The steady rate, with the time per request beside it and every release and interval that it rests on; the rate from the first batch's start; the rate with the start-up counted; the start-up; how long a request waits, from its batch's start to its release; from the last release to the program's end; the largest sample of the GPU's memory in use; the largest resident set of cp_prove; a proof's size; how many requests were served, failed or got no response; how many proofs cp_verify accepted, and a call's seconds. It takes no figure from what the programs print. Of the last line that cp_verify prints it passes on only the verdict's fixed words and a fault's name; the whole output is in checks/.

in the work directory, NEW_DIRECTORY what it is
report.txt the lines that the script printed
figures.json the same figures, with every time that they rest on: for each request, when it was seen to leave in/, its response's change and modification times, when the script first saw it, its size and its check
cp_prove.txt what cp_prove printed
requests/, checks/ the script's copies of the requests; what each call of cp_verify printed
spool/ the spool directory, with every response in out/
home/, tmp/ HOME and TMPDIR of cp_prove and of cp_verify. cp_verify's working directory is the work directory itself

Before you run it.

  • Each batch uses up one of the commitment's batches for good (how many it has). Measure on a commitment that was made for the measurement and serves nobody (Every day asks the same). Measure on synthetic weights or on a public model's files. With secret weights, a commitment made for the measurement is a further commitment to the same weights, which our judgement on weight hiding covers only on thin evidence and on conditions of its own (docs/limits.md).
  • The script reads nothing in the secret key directory: it passes the path on. So it cannot see whether a service is using that directory. It relies on cp_prove's own lock: a second cp_prove on a directory in use does not start. The script then prints that refusal, gives no rate and exits with code 1. The prover as a service says what that lock does not see, and the script prints it before it starts cp_prove.
  • The work directory keeps the requests, every response and both programs' output. Keep it as secret as the secret key directory and, with secret weights, what the script prints too: that is among what Operator's duties, "Every day" keeps private (cp_prove's exit code and, after a bad end, the last lines of its log). The work directory's spool/ is a spool directory, so do for it what Operator's duties asks for one: keep it on an encrypted disk, or on one that holds nothing else and that you will wipe or destroy (Keys, seeds and machines), and before you give it up run cp_prove -clear on spool/, and only on it (A new commitment, step 4; how). The work directory needs room for every proof: about 19 MB each at full size.
  • At full size, at 24 requests a batch, on the public 4-bit weight files, cp_prove needs about 257 GB of host memory for its own process and about 270 GB in its container, file cache not counted (the largest of 3 runs). If the system kills it for want of memory, nothing is wiped, and the commitment falls under When something goes wrong. --least-memory makes the script look before it starts anything. It looks once, so start nothing large beside it.
  • Start it in a session that outlives your connection, such as tmux, and set inside that session whatever shell variables, virtual environment and PATH your command line relies on.

What it never does. It removes nothing, in its work directory or elsewhere, except the temporary name under which each request is written before it is submitted (A request file, step 3). It writes only below the work directory. It sends no signal, and sets no time limit of its own on cp_prove or on the calls of cp_verify that it makes in step 6, so it waits as long as one of them hangs (A program that hangs). A call of nvidia-smi that has not answered after 10 seconds is left alone: the script calls nvidia-smi no more, and says so beside the GPU's figure, with that call's process ID. It never starts cp_prove a second time. It calls no sudo, needs no root rights and is not meant to be run under sudo; as root it works as the programs do, and says that it is root. It fetches nothing from a network.

To stop it early, press Ctrl-C once. Each program that the script starts has a session of its own, so the terminal's Ctrl-C reaches only the script. Before cp_prove is started, the script just ends, with code 1. While cp_prove runs, it creates the service's stop file, says so and waits: cp_prove takes no further batch, finishes the batch that it has taken and ends by itself. A service that is still starting removes a stop file without obeying it, so the script creates the file again whenever it is gone; one can be left behind in spool/. Once cp_prove has ended and the script checks the responses (step 6), Ctrl-C makes it start no further call of cp_verify, wait for those that run and give no rate. The script looks for a Ctrl-C for the last time just before it prints the figures: a later one changes nothing. From cp_prove's start on, it takes SIGTERM and a hang-up (SIGHUP) as it takes Ctrl-C, also under nohup, which shields the script from a hang-up only until then.

If the script itself fails or dies. If report.txt or figures.json cannot be written, as on a full disk, the run goes on, and the last lines say which file is not whole. After any other fault of its own while cp_prove runs, the script gives no rate. It says on standard error that cp_prove is still running, with its process ID, where its output goes and where the stop file belongs. Then it waits for cp_prove's end, says how it ended, shows its own fault and exits with code 1. If the script is killed, it can say nothing: cp_prove goes on and ends by itself after its N batches, and its last line in NEW_DIRECTORY/cp_prove.txt begins p258 end. In both cases do not kill cp_prove, and start no other on the commitment.

When it gives no rate. If a batch was not full, the number of batches seen was not N, two batches overlapped, a request failed or got no response, a response's tag or files were not as the service promises, a proof was not checked or not accepted (anything but exit code 0 with the last line YES), cp_prove's exit code was not 0, or the script was asked to stop after cp_prove's start and before it printed the figures. It then says which, and exits with code 1. After any exit code of cp_prove other than 0, follow When something goes wrong. Exit code 2 means a wrong call, a refused directory, a commitment ID that cp_verify -plan id does not form from --config and --ivk's key file, or less memory than --least-memory asks for: nothing was written, and cp_prove was not started. The look at the ID is one call of cp_verify -plan id, with a limit of 300 seconds. It sees neither the secret key directory nor a leaf file: under a secret key directory of another commitment the run goes on, and every proof is rejected. Exit code 0 means that the rates were printed.

What a run does not show. It shows a speed on one machine at one hour, by that machine's own clock. It shows nothing about soundness or weight hiding. The script does not record how busy other processes kept the machine during the run: note that yourself. RELEASE, stamp and seen, the three times that it prints for each release, are readings of that one clock, if the work directory lies on a disk of that machine: on a network file system a file's change time is the server's. If two of the three lie more than 2 seconds apart at a release, the script prints a line that begins NOTE: under the heading THE TIMES but holds back no figure for that: find out why they differ before you rely on a figure. If the clock is set back during the run, the steady rate can come out too high; if it is set forward, too low; and the report may show no sign of it. Each proof checks one token, the one after its window. The GPU's memory is sampled, so a peak between two samples is not seen. The kernel may take a file's change time from a clock that steps only every few milliseconds.

Details and record

Requirements. Both scripts need Linux and parse under Python 3.8 (by the syntax).

Tests. spool.py has no test of its own in this repository. The test of measure_rate.py is driver/tests/test_measure_rate.py, the row driver.measure_rate of ../SUITE.md. It runs the script on a CPU against stand-ins for cp_prove, cp_verify and nvidia-smi, which prove, check and measure nothing, so it does not show that the script works with the real programs.