Skip to main content Accueil Créateurs adu2021 skillxiv internvl3-5-multimodal-cascade-rl
internvl3-5-multimodal-cascade-rl Enhance multimodal models through cascade RL for reasoning improvement and visual resolution routing for inference efficiency, achieving 16% reasoning gains and 4.05x speedup.
Aller à l'installation Skills Marketplace Découvrez et explorez les compétences IA créées par la communauté.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Copier le promptAfficher les détails du prompt Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
npx skills add https://github.com/ADu2021/skillXiv --skill internvl3-5-multimodal-cascade-rlLa commande reste sur une seule ligne. Faites défiler horizontalement pour la vérifier avant de la copier.
Vous préférez une copie locale ? Téléchargez les fichiers actuellement disponibles dans SkillsMP.
Télécharger Zip Téléchargement... Métiers associés SOC
Basé sur la classification professionnelle SOC
name internvl3-5-multimodal-cascade-rl title InternVL3.5: Cascade RL and Visual Resolution Router for Multimodal Efficiency version 0.0.2 engine skillxiv-v0.0.2-claude-opus-4.6 license MIT url https://arxiv.org/abs/2508.18265 keywords ["multimodal-models","cascade-reinforcement-learning","visual-efficiency","reasoning","inference-optimization"] description Enhance multimodal models through cascade RL for reasoning improvement and visual resolution routing for inference efficiency, achieving 16% reasoning gains and 4.05x speedup.
InternVL3.5: Cascade RL and Visual Resolution Router
Core Concept
InternVL3.5 advances multimodal AI through two complementary techniques: Cascade RL for enhanced reasoning and Visual Resolution Router (ViR) for adaptive efficiency. Cascade RL combines offline RL for stable convergence with online RL for refined alignment, improving performance on visual reasoning benchmarks. ViR dynamically adjusts visual token resolution based on image complexity, maintaining performance while reducing computation. Together, these achieve 16% reasoning improvement and 4.05x inference speedup.
Architecture Overview
Cascade RL Framework : Two-stage training (offline → online)
Visual Resolution Router : Dynamic resolution selection per image
Decoupled Vision-Language Deployment : Distributed inference
Reasoning Enhancement : Improved visual understanding
Efficiency Optimization : Token reduction without quality loss
Implementation Steps
1. Implement Cascade RL Framework
Two-stage training for stable and effective policy learning:
import torch
import torch.nn as nn
from typing import Dict , List , Tuple
class CascadeRLTrainer :
"""Two-stage RL: offline stable convergence + online refinement."""
def __init__ (
self,
model: "MultimodalLLM" ,
offline_steps: int = 1000 ,
online_steps: int = 500 ,
offline_lr: float = 1e-5 ,
online_lr: float = 5e-6
):
self .model = model
self .offline_steps = offline_steps
self .online_steps = online_steps
.offline_optimizer = torch.optim.Adam(model.parameters(), lr=offline_lr)
.online_optimizer = torch.optim.Adam(model.parameters(), lr=online_lr)
.training_logs = { : [], : []}
( ) -> [ , ]:
( )
metrics = { : [], : []}
step ( .offline_steps):
batch = ._sample_batch(dataset, batch_size= )
outputs = .model(batch[ ], batch[ ])
logits = outputs.logits
rewards = ._compute_correctness_reward(
outputs.sequences,
batch[ ]
)
loss = ._compute_offline_loss(logits, rewards)
.offline_optimizer.zero_grad()
loss.backward()
torch.nn.utils.clip_grad_norm_( .model.parameters(), )
.offline_optimizer.step()
metrics[ ].append(loss.item())
metrics[ ].append(rewards.mean().item())
(step + ) % == :
avg_loss = (metrics[ ][- :]) /
avg_reward = (metrics[ ][- :]) /
( )
.training_logs[ ] = metrics
{ : (metrics[ ]) / (metrics[ ]),
: (metrics[ ]) / (metrics[ ])}
( ) -> [ , ]:
( )
metrics = { : [], : []}
episode (num_episodes):
state = env.reset()
episode_reward =
episode_steps =
step ( .online_steps):
action = .model.generate(
state[ ],
state[ ],
max_tokens=
)
next_state, reward, done = env.step(action)
._store_transition(state, action, reward, next_state, done)
loss = ._compute_online_loss(state, action, reward)
.online_optimizer.zero_grad()
loss.backward()
.online_optimizer.step()
episode_reward += reward
episode_steps +=
state = next_state
done:
metrics[ ].append(episode_reward)
metrics[ ].append(episode_steps)
(episode + ) % == :
avg_reward = (metrics[ ][- :]) /
( )
.training_logs[ ] = metrics
{ : (metrics[ ]) / (metrics[ ]),
: (metrics[ ]) / (metrics[ ])}
( ) -> torch.Tensor:
log_probs = torch.log_softmax(logits, dim=- )
policy_loss = -(log_probs.mean(dim= ) * rewards).mean()
regularization =
policy_loss + regularization
( ) -> torch.Tensor:
outputs = .model(state[ ], state[ ])
logits = outputs.logits
action_log_prob = ._get_log_prob_of_action(action, logits)
loss = -action_log_prob * reward
loss
( ) -> torch.Tensor:
rewards = []
pred, target (predictions, targets):
correct = pred.strip() == target.strip()
reward = correct -
rewards.append(reward)
torch.tensor(rewards)
( ):
random
batch_samples = random.sample(dataset, (batch_size, (dataset)))
{
: [s[ ] s batch_samples],
: [s[ ] s batch_samples],
: [s[ ] s batch_samples]
}
( ):
( ) -> torch.Tensor:
self
self
self
"offline"
"online"
def
offline_rl_phase
self,
dataset: List [Dict ],
reference_model: "MultimodalLLM" = None
Dict
str
float
"""
Offline RL: learn from fixed dataset without environment interaction.
Prioritizes stability over exploration.
"""
print
"Starting Offline RL Phase..."
"loss"
"reward"
for
in
range
self
self
8
self
"images"
"questions"
self
"answers"
self
self
self
1.0
self
"loss"
"reward"
if
1
100
0
sum
"loss"
100
100
sum
"reward"
100
100
print
f"Offline Step {step+1 } : Loss={avg_loss:.4 f} , Reward={avg_reward:.4 f} "
self
"offline"
return
"avg_loss"
sum
"loss"
len
"loss"
"avg_reward"
sum
"reward"
len
"reward"
def
online_rl_phase
self,
env: "VisualReasoning Env" ,
num_episodes: int = 100
Dict
str
float
"""
Online RL: interact with environment for refinement.
Fine-tunes policy on real interactions.
"""
print
"Starting Online RL Phase..."
"episode_reward"
"episode_length"
for
in
range
0
0
for
in
range
self
self
"image"
"question"
100
self
self
self
self
1
if
break
"episode_reward"
"episode_length"
if
1
10
0
sum
"episode_reward"
10
10
print
f"Online Episode {episode+1 } : Reward={avg_reward:.2 f} "
self
"online"
return
"avg_episode_reward"
sum
"episode_reward"
len
"episode_reward"
"avg_episode_length"
sum
"episode_length"
len
"episode_length"
def
_compute_offline_loss
self,
logits: torch.Tensor,
rewards: torch.Tensor
"""Offline RL loss: conservative policy update."""
1
1
0.0
return
def
_compute_online_loss
self,
state: Dict ,
action: str ,
reward: float
"""Online RL loss: standard policy gradient."""
self
"image"
"question"
self
return
def
_compute_correctness_reward
self,
predictions: List [str ],
targets: List [str ]
"""Compute reward based on answer correctness."""
for
in
zip
1.0
if
else
0.1
return
def
_sample_batch
self, dataset: List [Dict ], batch_size: int
"""Sample batch from dataset."""
import
min
len
return
"images"
"image"
for
in
"questions"
"question"
for
in
"answers"
"answer"
for
in
def
_store_transition
self, state, action, reward, next_state, done
pass
def
_get_log_prob_of_action
self, action: str , logits: torch.Tensor
pass
2. Implement Visual Resolution Router Dynamically adjust image resolution based on complexity:
class VisualResolutionRouter (nn.Module):
"""Adaptively select image resolution for efficiency."""
def __init__ (self, model: "MultimodalLLM" , resolution_options: List [int ] = [224 , 336 , 448 , 672 ] ):
super ().__init__()
self .model = model
self .resolution_options = sorted (resolution_options)
self .complexity_encoder = nn.Sequential(
nn.Conv2d(3 , 64 , kernel_size=3 , padding=1 ),
nn.ReLU(),
nn.AdaptiveAvgPool2d((1 , 1 )),
nn.Flatten(),
nn.Linear(64 , 32 ),
nn.ReLU(),
nn.Linear(32 , len (resolution_options))
)
def forward (
self,
images: torch.Tensor,
return_complexity: bool = False
) -> Tuple [torch.Tensor, List [int ]]:
"""
Select resolution for each image based on complexity.
"""
batch_size = images.shape[0 ]
normalized_images = torch.nn.functional.interpolate(
images,
size=(224 , 224 ),
mode='bilinear' ,
align_corners=False
)
complexity_logits = self .complexity_encoder(normalized_images)
complexity_probs = torch.softmax(complexity_logits, dim=-1 )
complexity_scores = torch.max (complexity_probs, dim=-1 )[1 ]
selected_resolutions = [
self .resolution_options[score.item()] for score in complexity_scores
]
resized_images = []
for img, res in zip (images, selected_resolutions):
resized = torch.nn.functional.interpolate(
img.unsqueeze(0 ),
size=(res, res),
mode='bilinear' ,
align_corners=False
).squeeze(0 )
resized_images.append(resized)
return resized_images, selected_resolutions
def train_router (
self,
train_images: List [torch.Tensor],
train_quality: List [float ],
num_epochs: int = 10
):
"""
Train router to balance quality and efficiency.
"""
optimizer = torch.optim.Adam(self .complexity_encoder.parameters(), lr=1e-4 )
for epoch in range (num_epochs):
total_loss = 0.0
for image, target_quality in zip (train_images, train_quality):
img_normalized = torch.nn.functional.interpolate(
image.unsqueeze(0 ),
size=(224 , 224 )
)
logits = self .complexity_encoder(img_normalized)
complexity_score = torch.softmax(logits, dim=-1 )
expected_quality = complexity_score * torch.tensor([0.7 , 0.8 , 0.9 , 1.0 ])
loss = torch.nn.functional.mse_loss(expected_quality.sum (), torch.tensor(target_quality))
optimizer.zero_grad()
loss.backward()
optimizer.step()
total_loss += loss.item()
if (epoch + 1 ) % 2 == 0 :
print (f"Router Training Epoch {epoch+1 } : Loss={total_loss/len (train_images):.4 f} " )
3. Implement Decoupled Deployment Separate vision and language models for distributed inference:
class DecoupledInference :
"""Vision and language models on separate GPUs for efficiency."""
def __init__ (
self,
vision_model: nn.Module,
language_model: nn.Module,
vision_device: str = "cuda:0" ,
language_device: str = "cuda:1"
):
self .vision_model = vision_model.to(vision_device)
self .language_model = language_model.to(language_device)
self .vision_device = vision_device
self .language_device = language_device
def forward (
self,
images: torch.Tensor,
questions: List [str ]
) -> List [str ]:
"""
Distributed forward pass: vision on GPU0, language on GPU1.
"""
images = images.to(self .vision_device)
with torch.no_grad():
vision_embeddings = self .vision_model(images)
vision_embeddings = vision_embeddings.to(self .language_device)
language_inputs = self .language_model.encode_multimodal(
vision_embeddings,
questions
)
responses = self .language_model.generate(language_inputs, max_length=100 )
return responses
def measure_throughput (
self,
num_examples: int = 100 ,
batch_size: int = 8
) -> Dict [str , float ]:
"""
Measure inference throughput with decoupled deployment.
"""
import time
start_time = time.time()
for _ in range (num_examples // batch_size):
dummy_images = torch.randn(batch_size, 3 , 224 , 224 )
dummy_questions = ["What is in the image?" ] * batch_size
_ = self .forward(dummy_images, dummy_questions)
elapsed = time.time() - start_time
throughput = num_examples / elapsed
return {
"throughput_examples_per_second" : throughput,
"latency_per_example_ms" : (elapsed / num_examples) * 1000 ,
"total_time_seconds" : elapsed
}
Practical Guidance
When to Use InternVL3.5 Techniques
Visual reasoning tasks (MMMU, MathVista)
Multimodal applications with efficiency constraints
GUI or document analysis with variable complexity
Production systems requiring inference optimization
Models needing both reasoning and speed
When NOT to Use
Single-image simple classification
Models without GPU distribution capability
Real-time ultra-low-latency systems (<50ms)
Tasks where resolution is critical and fixed
Key Hyperparameters
offline_rl_steps : 500-2000
online_rl_episodes : 50-200
resolution_options : [224, 336, 448, 672]
cascade_rl_weight : 0.5 for each phase
temperature (offline) : 0.7-1.0
Performance Expectations
Reasoning Improvement: +16.0%
Inference Speedup: 4.05x
Quality Preservation: 95%+ accuracy maintained
GPU Memory: Distributed across devices
Reference Researchers. (2024). InternVL3.5: Advancing Open-Source Multimodal Models. arXiv preprint arXiv:2508.18265.