### Minimal Test-Time Training Example Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/index.rst This example demonstrates the basic usage of test-time training with the torch-ttt library. Ensure you have the necessary imports and model setup before running. ```python import torch from torch_ttt.engine import TTTEngine from torch_ttt.models import ResNet18 # Dummy data and model data = torch.randn(16, 3, 32, 32) model = ResNet18() # Initialize TTT engine ttt_engine = TTTEngine(model) # Perform test-time training ttt_engine.forward(data) ``` -------------------------------- ### Quick Start: Test-Time Adaptation with TentEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/README.md A minimal example demonstrating how to use TentEngine for test-time adaptation of a pre-trained ResNet50 model. The engine adapts the model during the forward pass. ```python import torch import torchvision.models as models from torch_ttt.engine.tent_engine import TentEngine # Load your pre-trained model model = models.resnet50(pretrained=True) # Wrap it with a TTT Engine (e.g., TENT for entropy minimization) engine = TentEngine( model=model, optimization_parameters={ "lr": 2e-3, "num_steps": 1 } ) # Switch to eval mode engine.eval() # At test time, adapt to new data test_images = torch.randn(8, 3, 224, 224) # The engine automatically adapts the model during forward adapted_output = engine(test_images) ``` -------------------------------- ### Install Development Version from GitHub Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/installation.rst Install the latest development version of torch-ttt directly from its GitHub repository using pip. PyTorch must be installed beforehand. ```console pip install git+https://github.com/nikitadurasov/torch-ttt.git ``` -------------------------------- ### Install Latest Stable Release from PyPI Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/installation.rst Install the latest stable version of torch-ttt using pip. Ensure Python and PyTorch are already installed. ```console pip install torch-ttt ``` -------------------------------- ### Initialize Line Chart for Citations Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/scripts/data/papers_table.html Initializes a line chart using Chart.js to visualize citation trends per year and projected citations. This setup is used for the 'Citations per Year' plot. ```javascript const ctx = document.getElementById('citationsChart').getContext('2d'); new Chart(ctx, { type: 'line', data: { labels: [], datasets: [ { label: 'Citations per Year', data: [], borderWidth: 2, fill: true, tension: 0.3, }, { label: 'Projected Citations', data: [], borderDash: [5,5], borderWidth: 2, fill: false, tension: 0.3, } ] }, options: { responsive: true, layout: { padding: 0 }, plugins: { tooltip: { mode: 'index', intersect: false, callbacks: { label: function(context) { return `${context.dataset.label}: ${context.parsed.y}`; } } }, legend: { display: true } }, scales: { y: { beginAtZero: true, ticks: { precision: 0 } } }, hover: { mode: 'nearest', intersect: true } } }); ``` -------------------------------- ### Using TTTEngine for Training and Evaluation Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/index.rst Wrap your PyTorch model with TTTEngine to seamlessly integrate training and evaluation loops. Ensure the engine is correctly initialized with the model and a layer name. The optimizer should be configured to use the engine's parameters. ```python from torch_ttt.engine.ttt_engine import TTTEngine network = Net() engine = TTTEngine(network, "layer_name") # Wrap your model with the Engine optimizer = optim.Adam(engine.parameters(), lr=learning_rate) engine.train() ... # Train your model as usual engine.eval() ... # Test your model as usual ``` -------------------------------- ### Integrate TTTEngine into Training Loop Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/quickstart.rst Wrap your model with TTTEngine and include the TTT loss in your main loss function during training. Ensure the engine is in training mode. ```diff +from torch_ttt.engine.ttt_engine import TTTEngine model = MyModel() +engine = TTTEngine(model, features_layer_name='layer2') ...Setting up data, optimizers, etc... # Training loop - model.train() + engine.train() # Don't forget it, it's important! for batch in train_loader: inputs, targets = batch optimizer.zero_grad() - outputs = model(inputs) + outputs, loss_ttt = engine(inputs) - loss = loss_fn(outputs, targets) + loss = loss_fn(outputs, targets) + alpha * loss_ttt loss.backward() optimizer.step() ``` -------------------------------- ### Use TTTEngine for Inference Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/quickstart.rst Switch the TTTEngine to evaluation mode for inference. The engine will adapt the model to the provided inputs using TTT-based optimization. ```diff # Testing loop - model.eval() + engine.eval() # Also, don't forget it! for batch in test_loader: inputs, targets = batch optimizer.zero_grad() - outputs = model(inputs) + outputs = engine(inputs) metric = compute_metric(outputs, targets) ``` -------------------------------- ### MemoEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the MemoEngine for the torch-ttt library. ```APIDOC ## MemoEngine ### Description This class is part of the `torch_ttt.engine` module and represents the MemoEngine. ### Usage ```python from torch_ttt.engine import MemoEngine # Instantiate the engine engine = MemoEngine() ``` ``` -------------------------------- ### TTTEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the standard TTTEngine for the torch-ttt library. ```APIDOC ## TTTEngine ### Description This class is part of the `torch_ttt.engine` module and represents the standard TTTEngine. ### Usage ```python from torch_ttt.engine import TTTEngine # Instantiate the engine engine = TTTEngine() ``` ``` -------------------------------- ### TTTPPEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the TTTPPEngine for the torch-ttt library. ```APIDOC ## TTTPPEngine ### Description This class is part of the `torch_ttt.engine` module and represents the TTTPPEngine. ### Usage ```python from torch_ttt.engine import TTTPPEngine # Instantiate the engine engine = TTTPPEngine() ``` ``` -------------------------------- ### EataEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the EataEngine for the torch-ttt library. ```APIDOC ## EataEngine ### Description This class is part of the `torch_ttt.engine` module and represents the EataEngine. ### Usage ```python from torch_ttt.engine import EataEngine # Instantiate the engine engine = EataEngine() ``` ``` -------------------------------- ### TentEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the TentEngine for the torch-ttt library. ```APIDOC ## TentEngine ### Description This class is part of the `torch_ttt.engine` module and represents the TentEngine. ### Usage ```python from torch_ttt.engine import TentEngine # Instantiate the engine engine = TentEngine() ``` ``` -------------------------------- ### IT3Engine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the IT3Engine for the torch-ttt library. ```APIDOC ## IT3Engine ### Description This class is part of the `torch_ttt.engine` module and represents the IT3Engine. ### Usage ```python from torch_ttt.engine import IT3Engine # Instantiate the engine engine = IT3Engine() ``` ``` -------------------------------- ### DeYOEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the DeYOEngine for the torch-ttt library. ```APIDOC ## DeYOEngine ### Description This class is part of the `torch_ttt.engine` module and represents the DeYOEngine. ### Usage ```python from torch_ttt.engine import DeYOEngine # Instantiate the engine engine = DeYOEngine() ``` ``` -------------------------------- ### ActMADEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the ActMADEngine for the torch-ttt library. ```APIDOC ## ActMADEngine ### Description This class is part of the `torch_ttt.engine` module and represents the ActMADEngine. ### Usage ```python from torch_ttt.engine import ActMADEngine # Instantiate the engine engine = ActMADEngine() ``` ``` -------------------------------- ### MaskedTTTEngine Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/api.rst Represents the MaskedTTTEngine for the torch-ttt library. ```APIDOC ## MaskedTTTEngine ### Description This class is part of the `torch_ttt.engine` module and represents the MaskedTTTEngine. ### Usage ```python from torch_ttt.engine import MaskedTTTEngine # Instantiate the engine engine = MaskedTTTEngine() ``` ``` -------------------------------- ### Sort Papers by Different Criteria (JavaScript) Source: https://github.com/nikitadurasov/torch-ttt/blob/main/docs/scripts/data/papers_table.html This JavaScript function sorts paper entries displayed on the page based on user-selected criteria such as citations, trending status, year, conference, or title. It manipulates the DOM to reorder the paper cards. ```javascript function sortPapers() { const container = document.getElementById('papersContainer'); const cards = Array.from(container.getElementsByClassName('paper-card')); const sortValue = document.getElementById('sortSelect').value; cards.sort((a, b) => { if (sortValue === 'citations') { return parseInt(b.dataset.citations) - parseInt(a.dataset.citations); } else if (sortValue === 'trending') { return parseInt(b.dataset.trending) - parseInt(a.dataset.trending); } else if (sortValue === 'year') { return parseInt(b.dataset.year) - parseInt(a.dataset.year); } else if (sortValue === 'conference') { return a.dataset.conference.localeCompare(b.dataset.conference); } else if (sortValue === 'title') { return a.dataset.title.localeCompare(b.dataset.title); } }); container.innerHTML = ''; cards.forEach(card => container.appendChild(card)); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.