Neural Architecture Search Nas
# Neural Architecture Search (NAS)
## Introduction & Motivation
NAS: automated neural network design. Reinforcement learning-based search, evolutionary algorithms. Applications: efficient model discovery, AutoML.
Motivation: Automate architecture design for optimal performance.
Applications: Mobile-optimized models, domain-specific architectures.
---
## Core Concepts & Theory
### Search Space
Possible architecture configurations.
### Search Strategy
RL, evolutionary, gradient-based.
### Performance Estimation
Accuracy prediction acceleration.
### Multi-Objective Optimization
Balance accuracy and efficiency.
---
## Mathematical Formulation
Architecture Space:
$$\mathcal{A} = \{a | a \in A_1 imes A_2 imes ... imes A_n\}$$
Controller Loss:
$$\mathcal{L} = -\mathbb{E}[R(a)]$$
Reward Signal:
$$R(a) = ext{Accuracy}(a) - \lambda \cdot ext{Latency}(a)$$
---
## Advanced Theory & Extensions
### Differentiable NAS
Gradient-based architecture search.
### Efficient NAS
Reduced search cost via supernets.
### Zero-Cost Proxies
Rapid architecture evaluation.
---
## Computational Considerations
Search: O(S·T·E) (S=space, T=training time).
Controller: O(K·D) (K=samples, D=controller dim).
Total: Days to weeks of search.
---
## Practical Implementation Strategies
### Early Stopping
Reduce evaluation cost.
### Weight Sharing
Supernet training efficiency.
### Knowledge Distillation
Compress discovered architecture.
---
## Benchmark Datasets & Evaluation
ImageNet: Architecture benchmark.
CIFAR-10: Quick evaluation.
Mobile settings: Hardware-specific optimization.
---
## Key Challenges & Limitations
### Search Cost
Computationally expensive exploration.
### Transferability
Architecture generalization across tasks.
### Reproducibility
High variance in results.
---
## Hyperparameter Tuning
Search iterations: 100-500.
Population size: 20-100.
Mutation rate: 0.1-0.3.
---
## Real-World Applications & Case Studies
Mobile Deployment: MobileNetV3 via NAS.
Edge Computing: Efficient architectures.
Medical Imaging: Specialized architecture discovery.
---
## Integration with Other Methods
NAS + knowledge distillation; + pruning for deployment.
---
## Summary & Key Takeaways
Neural Architecture Search automates optimal model discovery.
Principles:
1. Search space: Possible configurations.
2. Search strategy: Exploration algorithm.
3. Performance estimation: Efficiency tricks.
4. Multi-objective: Balance multiple goals.
5. Automation: Reduce manual tuning.
---
## Appendix: Practical Labs
### Lab 1: Search Space Definition
import numpy as np
def define_search_space():
"""Define NAS search space"""
layers = [16, 32, 64, 128]
kernels = [3, 5, 7]
activations = ['relu', 'swish']
search_space = {
'depth': list(range(3, 8)),
'width': layers,
'kernel_size': kernels,
'activation': activations
}
return search_space
space = define_search_space()
assert 'depth' in space, "Search space defined"
print(f"✓ Search space: {len(space)} dimensions")### Lab 2: Random Architecture Sampling
import numpy as np
def sample_random_architecture(search_space):
"""Sample random architecture from search space"""
architecture = {
'depth': np.random.choice(search_space['depth']),
'width': np.random.choice(search_space['width']),
'kernel_size': np.random.choice(search_space['kernel_size']),
'activation': np.random.choice(search_space['activation'])
}
return architecture
np.random.seed(42)
space = {'depth': [3, 4, 5, 6], 'width': [16, 32], 'kernel_size': [3, 5], 'activation': ['relu', 'swish']}
arch = sample_random_architecture(space)
assert isinstance(arch, dict), "Architecture sampled"
print(f"✓ Sampled architecture: {arch}")### Lab 3: Architecture Encoding
import numpy as np
def encode_architecture(architecture, search_space):
"""Encode architecture to vector"""
encoding = []
for key, value in architecture.items():
idx = search_space[key].index(value) if isinstance(search_space[key][0], str) else np.where(np.array(search_space[key]) == value)[0][0]
encoding.append(idx)
return np.array(encoding)
np.random.seed(42)
space = {'depth': [3, 4, 5], 'width': [16, 32], 'kernel': [3, 5], 'act': ['relu', 'swish']}
arch = {'depth': 4, 'width': 32, 'kernel': 3, 'act': 'relu'}
encoding = encode_architecture(arch, space)
assert len(encoding) == 4, "Correct encoding"
print("✓ Architecture encoding working")### Lab 4: Multi-Objective Scoring
import numpy as np
def multi_objective_score(accuracy, latency, lambda_param=0.1):
"""Compute multi-objective reward"""
score = accuracy - lambda_param * latency
return score
accuracy = 0.95
latency = 100 # ms
score = multi_objective_score(accuracy, latency, lambda_param=0.001)
assert isinstance(score, (int, float, np.number)), "Valid score"
print(f"✓ Multi-objective score: {score:.4f}")---