mirror of
https://github.com/bigscience-workshop/petals
synced 2024-10-31 09:20:41 +00:00
cb3f018f9f
This PR: 1. **Abolishes the model conversion procedure.** Now, models are downloaded directly from original repositories like https://huggingface.co/bigscience/bloom. Servers download only shards with blocks to be hosted, and clients download only shards with input/output embeddings and layernorms. - BLOOM is loaded from `bigscience/bloom`, but we use the DHT prefix `bigscience/bloom-petals` for backward compatibility. Same with smaller BLOOMs and BLOOMZ. - LLaMA can be loaded from any repo like `username/llama-65b-hf`, but we use the DHT prefix `llama-65b-hf` (without the username) to accomodate blocks from different repos (there're a few of them with minor differences, such as `Llama` vs. `LLaMA` in the class name). 2. **Refactors the client to generalize it for multiple models.** Now, we have `petals.models` packages that contain model-specific code (e.g. `petals.models.bloom`, `petals.models.llama`). General code (e.g. CPU-efficient LM head, p-tuning) is kept in `petals.client`. 3. **Introduces** `WrappedLlamaBlock`, `DistributedLlamaConfig`, `DistributedLlamaForCausalLM`, `DistributedLlamaForSequenceClassification`, and `DistributedLlamaModel` compatible with Petals functionality (p-tuning, adapters, etc.). 4. **Introduces** `AutoDistributedConfig` that automatically chooses the correct config class (`DistributedLlamaConfig` or `DistributedBloomConfig`). The refactored configs contain all model-specific info for both clients and servers. Upgrade instructions: - Remove disk caches for blocks in old (converted) format to save disk space. That is, remove `~/.cache/petals/model--bigscience--bloom-petals` and `~/.cache/petals/model--bigscience--bloomz-petals` directories (if present).
38 lines
1.7 KiB
Python
38 lines
1.7 KiB
Python
import time
|
|
|
|
import hivemind
|
|
import pytest
|
|
import torch
|
|
|
|
from petals import DistributedBloomConfig, RemoteSequential
|
|
from petals.server.handler import CACHE_TOKENS_AVAILABLE
|
|
from test_utils import *
|
|
|
|
|
|
@pytest.mark.forked
|
|
def test_server_info(block_from: int = 22, block_to: int = 24, max_length: int = 100, max_length2: int = 50):
|
|
config = DistributedBloomConfig.from_pretrained(MODEL_NAME)
|
|
dht = hivemind.DHT(initial_peers=INITIAL_PEERS, client_mode=True, start=True)
|
|
blocks1 = RemoteSequential(config, dht=dht, start_block=block_from, end_block=block_to)
|
|
blocks2 = RemoteSequential(config, dht=dht, start_block=block_to - 1, end_block=block_to)
|
|
|
|
info_before = blocks1.sequence_manager.rpc_info
|
|
|
|
with blocks1.inference_session(max_length=max_length) as sess:
|
|
sess.step(torch.randn(1, 1, config.hidden_size))
|
|
blocks1.sequence_manager.state.rpc_info = None # invalidate cache
|
|
info_inside = blocks1.sequence_manager.rpc_info
|
|
|
|
with blocks2.inference_session(max_length=max_length2) as sess2:
|
|
sess2.step(torch.randn(1, 1, config.hidden_size))
|
|
blocks2.sequence_manager.state.rpc_info = None # invalidate cache
|
|
info_inside2 = blocks2.sequence_manager.rpc_info
|
|
|
|
time.sleep(0.1)
|
|
blocks1.sequence_manager.state.rpc_info = None # invalidate cache
|
|
info_after = blocks1.sequence_manager.rpc_info
|
|
|
|
assert info_before[CACHE_TOKENS_AVAILABLE] == info_after[CACHE_TOKENS_AVAILABLE]
|
|
assert info_before[CACHE_TOKENS_AVAILABLE] - info_inside[CACHE_TOKENS_AVAILABLE] == max_length * len(blocks1)
|
|
assert info_inside[CACHE_TOKENS_AVAILABLE] - info_inside2[CACHE_TOKENS_AVAILABLE] == max_length2 * len(blocks2)
|