profiling

This commit is contained in:
Ruilong Li committed 2023-04-06 20:30:56 +00:00
1 parent ec603634ed
commit 07698dfb71
8 files changed
+19

No files matched your search

+4
View File
@@ -35,6 +35,7 @@ from nerfstudio.cameras.rays import RayBundle
from nerfstudio.data.scene_box import SceneBox from nerfstudio.data.scene_box import SceneBox
from nerfstudio.utils.misc import strtobool from nerfstudio.utils.misc import strtobool
from nerfstudio.utils.tensor_dataclass import TensorDataclass from nerfstudio.utils.tensor_dataclass import TensorDataclass
from nerfstudio.utils import profiler
TORCH_DEVICE = Union[torch.device, str] # pylint: disable=invalid-name TORCH_DEVICE = Union[torch.device, str] # pylint: disable=invalid-name
@@ -309,6 +310,8 @@ class Cameras(TensorDataclass):
image_coords = torch.stack(image_coords, dim=-1) + pixel_offset # stored as (y, x) coordinates image_coords = torch.stack(image_coords, dim=-1) + pixel_offset # stored as (y, x) coordinates
return image_coords return image_coords
@profiler.time_function
@profile
def generate_rays( # pylint: disable=too-many-statements def generate_rays( # pylint: disable=too-many-statements
self, self,
camera_indices: Union[TensorType["num_rays":..., "num_cameras_batch_dims"], int], camera_indices: Union[TensorType["num_rays":..., "num_cameras_batch_dims"], int],
@@ -487,6 +490,7 @@ class Cameras(TensorDataclass):
return raybundle return raybundle
# pylint: disable=too-many-statements # pylint: disable=too-many-statements
@profile
def _generate_rays_from_coords( def _generate_rays_from_coords(
self, self,
camera_indices: TensorType["num_rays":..., "num_cameras_batch_dims"], camera_indices: TensorType["num_rays":..., "num_cameras_batch_dims"],
@@ -71,6 +71,7 @@ from nerfstudio.data.utils.nerfstudio_collate import nerfstudio_collate
from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes
from nerfstudio.model_components.ray_generators import RayGenerator from nerfstudio.model_components.ray_generators import RayGenerator
from nerfstudio.utils.misc import IterableWrapper from nerfstudio.utils.misc import IterableWrapper
from nerfstudio.utils import profiler
CONSOLE = Console(width=120) CONSOLE = Console(width=120)
@@ -510,6 +511,8 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
num_workers=self.world_size * 4, num_workers=self.world_size * 4,
) )
@profiler.time_function
@profile
def next_train(self, step: int) -> Tuple[RayBundle, Dict]: def next_train(self, step: int) -> Tuple[RayBundle, Dict]:
"""Returns the next batch of data from the train dataloader.""" """Returns the next batch of data from the train dataloader."""
self.train_count += 1 self.train_count += 1
+2
View File
@@ -21,6 +21,7 @@ from typing import Dict, Optional, Union
import torch import torch
from torchtyping import TensorType from torchtyping import TensorType
from nerfstudio.utils import profiler
class PixelSampler: # pylint: disable=too-few-public-methods class PixelSampler: # pylint: disable=too-few-public-methods
@@ -182,6 +183,7 @@ class PixelSampler: # pylint: disable=too-few-public-methods
return collated_batch return collated_batch
@profiler.time_function
def sample(self, image_batch: Dict): def sample(self, image_batch: Dict):
"""Sample an image batch and return a pixel batch. """Sample an image batch and return a pixel batch.
@@ -21,6 +21,7 @@ from torchtyping import TensorType
from nerfstudio.cameras.camera_optimizers import CameraOptimizer from nerfstudio.cameras.camera_optimizers import CameraOptimizer
from nerfstudio.cameras.cameras import Cameras from nerfstudio.cameras.cameras import Cameras
from nerfstudio.cameras.rays import RayBundle from nerfstudio.cameras.rays import RayBundle
from nerfstudio.utils import profiler
class RayGenerator(nn.Module): class RayGenerator(nn.Module):
@@ -38,6 +39,8 @@ class RayGenerator(nn.Module):
self.pose_optimizer = pose_optimizer self.pose_optimizer = pose_optimizer
self.register_buffer("image_coords", cameras.get_image_coords(), persistent=False) self.register_buffer("image_coords", cameras.get_image_coords(), persistent=False)
@profiler.time_function
@profile
def forward(self, ray_indices: TensorType["num_rays", 3]) -> RayBundle: def forward(self, ray_indices: TensorType["num_rays", 3]) -> RayBundle:
"""Index into the cameras to generate the rays. """Index into the cameras to generate the rays.
+2
View File
@@ -33,6 +33,7 @@ from nerfstudio.configs.config_utils import to_immutable_dict
from nerfstudio.data.scene_box import SceneBox from nerfstudio.data.scene_box import SceneBox
from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes
from nerfstudio.model_components.scene_colliders import NearFarCollider from nerfstudio.model_components.scene_colliders import NearFarCollider
from nerfstudio.utils import profiler
# Model related configs # Model related configs
@@ -126,6 +127,7 @@ class Model(nn.Module):
Outputs of model. (ie. rendered colors) Outputs of model. (ie. rendered colors)
""" """
@profiler.time_function
def forward(self, ray_bundle: RayBundle) -> Dict[str, torch.Tensor]: def forward(self, ray_bundle: RayBundle) -> Dict[str, torch.Tensor]:
"""Run forward starting with a ray bundle. This outputs different things depending on the configuration """Run forward starting with a ray bundle. This outputs different things depending on the configuration
of the model and whether or not the batch is provided (whether or not we are training basically) of the model and whether or not the batch is provided (whether or not we are training basically)
+4
View File
@@ -60,6 +60,7 @@ from nerfstudio.model_components.scene_colliders import NearFarCollider
from nerfstudio.model_components.shaders import NormalsShader from nerfstudio.model_components.shaders import NormalsShader
from nerfstudio.models.base_model import Model, ModelConfig from nerfstudio.models.base_model import Model, ModelConfig
from nerfstudio.utils import colormaps from nerfstudio.utils import colormaps
from nerfstudio.utils import profiler
@dataclass @dataclass
@@ -262,6 +263,7 @@ class NerfactoModel(Model):
) )
return callbacks return callbacks
@profiler.time_function
def get_outputs(self, ray_bundle: RayBundle): def get_outputs(self, ray_bundle: RayBundle):
ray_samples, weights_list, ray_samples_list = self.proposal_sampler(ray_bundle, density_fns=self.density_fns) ray_samples, weights_list, ray_samples_list = self.proposal_sampler(ray_bundle, density_fns=self.density_fns)
field_outputs = self.field(ray_samples, compute_normals=self.config.predict_normals) field_outputs = self.field(ray_samples, compute_normals=self.config.predict_normals)
@@ -305,6 +307,7 @@ class NerfactoModel(Model):
return outputs return outputs
@profiler.time_function
def get_metrics_dict(self, outputs, batch): def get_metrics_dict(self, outputs, batch):
metrics_dict = {} metrics_dict = {}
image = batch["image"].to(self.device) image = batch["image"].to(self.device)
@@ -313,6 +316,7 @@ class NerfactoModel(Model):
metrics_dict["distortion"] = distortion_loss(outputs["weights_list"], outputs["ray_samples_list"]) metrics_dict["distortion"] = distortion_loss(outputs["weights_list"], outputs["ray_samples_list"])
return metrics_dict return metrics_dict
@profiler.time_function
def get_loss_dict(self, outputs, batch, metrics_dict=None): def get_loss_dict(self, outputs, batch, metrics_dict=None):
loss_dict = {} loss_dict = {}
image = batch["image"].to(self.device) image = batch["image"].to(self.device)
+1
View File
@@ -266,6 +266,7 @@ class VanillaPipeline(Pipeline):
return self.model.device return self.model.device
@profiler.time_function @profiler.time_function
@profile
def get_train_loss_dict(self, step: int): def get_train_loss_dict(self, step: int):
"""This function gets your training loss dict. This will be responsible for """This function gets your training loss dict. This will be responsible for
getting the next batch of data from the DataManager and interfacing with the getting the next batch of data from the DataManager and interfacing with the
BIN
View File
Binary file not shown.