[Models] Improve iteration over layers (#19497)
Signed-off-by: Lukas Geiger <lukas.geiger94@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
"""Inference-only Gemma model compatible with HuggingFace weights."""
|
||||
from collections.abc import Iterable
|
||||
from functools import cache
|
||||
from itertools import islice
|
||||
from typing import Optional, Union
|
||||
|
||||
import torch
|
||||
@@ -308,7 +309,7 @@ class GemmaModel(nn.Module):
|
||||
else:
|
||||
hidden_states = intermediate_tensors["hidden_states"]
|
||||
residual = intermediate_tensors["residual"]
|
||||
for layer in self.layers[self.start_layer:self.end_layer]:
|
||||
for layer in islice(self.layers, self.start_layer, self.end_layer):
|
||||
hidden_states, residual = layer(
|
||||
positions,
|
||||
hidden_states,
|
||||
|
||||
Reference in New Issue
Block a user