ablation
ablation
¶
Ablation-CAM visual attribution.
reduce_scores_per_sample
¶
Average objective scores over all non-batch dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores
|
Tensor
|
Objective scores with the observation batch as leading axis. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Per-sample scores with shape |
Source code in src/versatil/explainability/attribution/ablation.py
repeat_observation_batch
¶
Repeat observation batch rows for channel-wise ablations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
ObservationBatch
|
Observation values keyed by observation name. |
required |
repeat_count
|
int
|
Number of repeated copies to concatenate along batch. |
required |
Returns:
| Type | Description |
|---|---|
ObservationBatch
|
Observation dictionary with tensor batch dimensions multiplied by |
ObservationBatch
|
|
ObservationBatch
|
repeated along the same batch axis so policy preprocessing sees a |
ObservationBatch
|
consistent batch size. |
Source code in src/versatil/explainability/attribution/ablation.py
replace_target_output
¶
Replace the selected target-layer output with an ablated tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_output
|
TensorModuleOutput
|
Original module output from the forward hook. |
required |
replacement
|
Tensor
|
Ablated tensor in the same layout as the selected output. |
required |
output_index
|
int | None
|
Optional tuple output index. |
required |
Returns:
| Type | Description |
|---|---|
TensorModuleOutput
|
Module output with the selected tensor replaced. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no replaceable tensor is present. |
Source code in src/versatil/explainability/attribution/ablation.py
ablate_target_channels
¶
Zero one target activation channel per repeated batch group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_output
|
TensorModuleOutput
|
Target module output from the forward hook. |
required |
camera_target
|
CameraExplanationTarget
|
Concrete camera target whose activation should be perturbed. |
required |
channel_start
|
int
|
First channel index ablated in this chunk. |
required |
channel_count
|
int
|
Number of channels ablated in this chunk. |
required |
sample_count
|
int
|
Number of original batch rows before repetition. |
required |
Returns:
| Type | Description |
|---|---|
TensorModuleOutput
|
Module output with one channel zeroed in each repeated batch group. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target activation cannot be converted to NCHW. |
RuntimeError
|
If the selected module output cannot be replaced. |
Source code in src/versatil/explainability/attribution/ablation.py
compute_ablation_maps_for_policy
¶
compute_ablation_maps_for_policy(policy, observation, actions=None, output_selector=None, target_camera=None, target_vision_module_names=None, channel_batch_size=32, preprocess_observation=True)
Compute Ablation-CAM maps for policy visual modules.
Note
Ablation-CAM is perturbation-based: each channel in the selected visual target activation is zeroed and the channel weight is the resulting drop in the selected prediction score, computed per batch sample. It is kept separate from gradient methods because it does not use backpropagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
Policy
|
Policy instance to explain. |
required |
observation
|
ObservationBatch
|
Raw observation tensors keyed by camera names. Camera
tensors must have shape |
required |
actions
|
ActionBatch | None
|
Optional action tensors. Discrete predictors use tokenized actions when available; otherwise pseudo-target tokens are generated before attribution hooks are registered. |
None
|
output_selector
|
PolicyPredictionSelector | None
|
Optional function selecting the prediction tensor to score for continuous predictors. |
None
|
target_camera
|
str | None
|
Optional camera key to explain. If omitted, every camera exposed by a visual module is explained. |
None
|
target_vision_module_names
|
list[str] | None
|
Optional visual module allowlist. |
None
|
channel_batch_size
|
int
|
Number of feature channels ablated per forward pass. |
32
|
preprocess_observation
|
bool
|
Whether to normalize/tokenize |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Heatmaps keyed by camera with shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If a camera tensor has an unsupported rank. |
RuntimeError
|
If the selected visual module does not expose a compatible explainability target. |
RuntimeError
|
If target-layer activation capture fails. |
RuntimeError
|
If the captured activation batch is not divisible by the observation batch. |
Source code in src/versatil/explainability/attribution/ablation.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |