Text Generation
Transformers
PEFT
English
music
guitar
piano
drums
vocals
music-theory
ear-training
songwriting
lora
qwen
eq-adapter
matrix-corp
Instructions to use Matrix-Corp/TouchGrass-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Matrix-Corp/TouchGrass-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Matrix-Corp/TouchGrass-7b")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Matrix-Corp/TouchGrass-7b", device_map="auto") - PEFT
How to use Matrix-Corp/TouchGrass-7b with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Matrix-Corp/TouchGrass-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Matrix-Corp/TouchGrass-7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Matrix-Corp/TouchGrass-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Matrix-Corp/TouchGrass-7b
- SGLang
How to use Matrix-Corp/TouchGrass-7b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Matrix-Corp/TouchGrass-7b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Matrix-Corp/TouchGrass-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Matrix-Corp/TouchGrass-7b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Matrix-Corp/TouchGrass-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Matrix-Corp/TouchGrass-7b with Docker Model Runner:
docker model run hf.co/Matrix-Corp/TouchGrass-7b
| """ | |
| Pytest configuration and shared fixtures for TouchGrass tests. | |
| """ | |
| import pytest | |
| import torch | |
| from pathlib import Path | |
| def project_root(): | |
| """Return the project root directory.""" | |
| return Path(__file__).parent.parent | |
| def test_data_dir(project_root): | |
| """Return the test data directory.""" | |
| data_dir = project_root / "tests" / "data" | |
| data_dir.mkdir(parents=True, exist_ok=True) | |
| return data_dir | |
| def sample_music_tokens(): | |
| """Return a list of sample music tokens.""" | |
| return [ | |
| "[GUITAR]", "[PIANO]", "[DRUMS]", "[VOCALS]", "[THEORY]", "[PRODUCTION]", | |
| "[FRUSTRATED]", "[CONFUSED]", "[EXCITED]", "[CONFIDENT]", | |
| "[EASY]", "[MEDIUM]", "[HARD]", | |
| "[TAB]", "[CHORD]", "[SCALE]", "[INTERVAL]", "[PROGRESSION]", | |
| "[SIMPLIFY]", "[ENCOURAGE]" | |
| ] | |
| def sample_qa_pair(): | |
| """Return a sample QA pair for testing.""" | |
| return { | |
| "category": "guitar", | |
| "messages": [ | |
| {"role": "system", "content": "You are a guitar assistant."}, | |
| {"role": "user", "content": "How do I play a G major chord?"}, | |
| {"role": "assistant", "content": "Place your middle finger on the 3rd fret of the 6th string, index on 2nd fret of 5th string, and ring/pinky on 3rd fret of the 1st and 2nd strings."} | |
| ] | |
| } | |
| def mock_tokenizer(): | |
| """Create a mock tokenizer for testing.""" | |
| class MockTokenizer: | |
| def __init__(self): | |
| self.vocab_size = 32000 | |
| self.pad_token_id = 0 | |
| def encode(self, text, **kwargs): | |
| # Simple mock encoding | |
| return [1, 2, 3, 4, 5] | |
| def decode(self, token_ids, **kwargs): | |
| return "mocked decoded text" | |
| def add_special_tokens(self, tokens_dict): | |
| self.vocab_size += len(tokens_dict.get("additional_special_tokens", [])) | |
| def add_tokens(self, tokens): | |
| if isinstance(tokens, list): | |
| self.vocab_size += len(tokens) | |
| else: | |
| self.vocab_size += 1 | |
| def convert_tokens_to_ids(self, token): | |
| return 32000 if token.startswith("[") else 1 | |
| return MockTokenizer() | |
| def device(): | |
| """Return the device to use for tests.""" | |
| return "cuda" if torch.cuda.is_available() else "cpu" | |
| def d_model(): | |
| """Return the model dimension for tests.""" | |
| return 768 | |
| def batch_size(): | |
| """Return the batch size for tests.""" | |
| return 4 | |
| def seq_len(): | |
| """Return the sequence length for tests.""" | |
| return 10 | |
| def music_theory_module(device, d_model): | |
| """Create a MusicTheoryModule instance for testing.""" | |
| from TouchGrass.models.music_theory_module import MusicTheoryModule | |
| module = MusicTheoryModule(d_model=d_model).to(device) | |
| module.eval() | |
| return module | |
| def tab_chord_module(device, d_model): | |
| """Create a TabChordModule instance for testing.""" | |
| from TouchGrass.models.tab_chord_module import TabChordModule | |
| module = TabChordModule(d_model=d_model).to(device) | |
| module.eval() | |
| return module | |
| def ear_training_module(device, d_model): | |
| """Create an EarTrainingModule instance for testing.""" | |
| from TouchGrass.models.ear_training_module import EarTrainingModule | |
| module = EarTrainingModule(d_model=d_model).to(device) | |
| module.eval() | |
| return module | |
| def eq_adapter_module(device, d_model): | |
| """Create a MusicEQAdapter instance for testing.""" | |
| from TouchGrass.models.eq_adapter import MusicEQAdapter | |
| module = MusicEQAdapter(d_model=d_model).to(device) | |
| module.eval() | |
| return module | |
| def songwriting_module(device, d_model): | |
| """Create a SongwritingModule instance for testing.""" | |
| from TouchGrass.models.songwriting_module import SongwritingModule | |
| module = SongwritingModule(d_model=d_model).to(device) | |
| module.eval() | |
| return module | |
| def music_qa_generator(): | |
| """Create a MusicQAGenerator instance for testing.""" | |
| from TouchGrass.data.music_qa_generator import MusicQAGenerator | |
| generator = MusicQAGenerator() | |
| return generator | |
| def chat_formatter(): | |
| """Create a ChatFormatter instance for testing.""" | |
| from TouchGrass.data.chat_formatter import ChatFormatter | |
| formatter = ChatFormatter() | |
| return formatter | |
| def touchgrass_loss(): | |
| """Create a TouchGrassLoss instance for testing.""" | |
| from TouchGrass.training.losses import TouchGrassLoss | |
| loss_fn = TouchGrassLoss(lm_loss_weight=1.0, eq_loss_weight=0.1, music_module_loss_weight=0.05) | |
| return loss_fn | |
| def pytest_configure(config): | |
| """Configure pytest with custom markers.""" | |
| config.addinivalue_line( | |
| "markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')" | |
| ) | |
| config.addinivalue_line( | |
| "markers", "integration: marks tests as integration tests" | |
| ) | |
| config.addinivalue_line( | |
| "markers", "gpu: marks tests that require GPU" | |
| ) | |
| def pytest_collection_modifyitems(config, items): | |
| """Modify test collection to add markers based on file names.""" | |
| for item in items: | |
| if "test_inference" in item.nodeid: | |
| item.add_marker(pytest.mark.integration) | |
| if "test_trainer" in item.nodeid: | |
| item.add_marker(pytest.mark.slow) | |